Problem with Laravel5 Views

Hello,
I started to learn laravel5 under homestead/vagrant, I'm having an issue with views, it shows me 403 Forbidden

Here is my routes:
Route::get('/', 'WelcomeController@index');

Route::get('home', 'HomeController@index');

Open in new window


here is my WelcomeController.php

<?php namespace App\Http\Controllers;

class WelcomeController extends Controller {

	/*
	|--------------------------------------------------------------------------
	| Welcome Controller
	|--------------------------------------------------------------------------
	|
	| This controller renders the "marketing page" for the application and
	| is configured to only allow guests. Like most of the other sample
	| controllers, you are free to modify or remove it as you desire.
	|
	*/

	/**
	 * Create a new controller instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		$this->middleware('guest');
	}

	/**
	 * Show the application welcome screen to the user.
	 *
	 * @return Response
	 */
	public function index()
	{
		return view('welcome');
	}

}

Open in new window



here is my welcome.blade.php view it is inside the views folder of course

{{'Hello.'}}

Open in new window


any idea?
adra750Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott MadeiraCommented:
Step 1 is to determine if it is a laravel problem or a web server problem.  Create a phpinfo.php file and put it in the public folder.  Contents of the file should be:

<?php
phpinfo();

Go to your site:   example.com/phpinfo.php  If you see the phpinfo page then the server is fine and we have a laravel issue.

The next thing to look at is the view.  They changed blade / views in laravel 5 and where in laravel 4.x you used to use {{  }}  with stuff in between you now use {!! !!} with stuff in between in your view files.
adra750Author Commented:
I created the php file, everything is good, I tried the {!! !!} didn't work either, i'm under OS X, I have laravel installed in vagrant box, everything was working fine until I decided to use the correct manipulation of putting my html/php files into views and keep only the css/pics in the public folder as you have answered before to a previous question, I'm trying to get just the "hello" echoed back, but i don't know what's going on, I thought about permissions, but i think it's fine, I attached the screenshot, you can check it

PHP Version 5.6.6-1+deb.sury.org~utopic+1

System	Linux homestead 3.16.0-23-generic #31-Ubuntu SMP Tue Oct 21 17:56:17 UTC 2014 x86_64
Build Date	Feb 20 2015 11:31:04
Server API	FPM/FastCGI
Virtual Directory Support	disabled
Configuration File (php.ini) Path	/etc/php5/fpm
Loaded Configuration File	/etc/php5/fpm/php.ini
Scan this dir for additional .ini files	/etc/php5/fpm/conf.d
Additional .ini files parsed	/etc/php5/fpm/conf.d/05-opcache.ini, /etc/php5/fpm/conf.d/10-mysqlnd.ini, /etc/php5/fpm/conf.d/10-pdo.ini, /etc/php5/fpm/conf.d/20-apcu.ini, /etc/php5/fpm/conf.d/20-curl.ini, /etc/php5/fpm/conf.d/20-gd.ini, /etc/php5/fpm/conf.d/20-gmp.ini, /etc/php5/fpm/conf.d/20-imap.ini, /etc/php5/fpm/conf.d/20-json.ini, /etc/php5/fpm/conf.d/20-mailparse.ini, /etc/php5/fpm/conf.d/20-mcrypt.ini, /etc/php5/fpm/conf.d/20-memcached.ini, /etc/php5/fpm/conf.d/20-mysql.ini, /etc/php5/fpm/conf.d/20-mysqli.ini, /etc/php5/fpm/conf.d/20-pdo_mysql.ini, /etc/php5/fpm/conf.d/20-pdo_pgsql.ini, /etc/php5/fpm/conf.d/20-pdo_sqlite.ini, /etc/php5/fpm/conf.d/20-pgsql.ini, /etc/php5/fpm/conf.d/20-readline.ini, /etc/php5/fpm/conf.d/20-redis.ini, /etc/php5/fpm/conf.d/20-sqlite3.ini, /etc/php5/fpm/conf.d/20-xdebug.ini, /etc/php5/fpm/conf.d/90-blackfire.ini
PHP API	20131106
PHP Extension	20131226
Zend Extension	220131226
Zend Extension Build	API220131226,NTS
PHP Extension Build	API20131226,NTS
Debug Build	

Open in new window



....long page info
Screen-Shot-2015-05-04-at-9.50.32-PM.png
Scott MadeiraCommented:
It should work.  I just verified it here on my box and even the {{ }} worked.  Check the log files in storage/logs to see if any errors are getting logged.  I assume you have errors and exceptions coming to the screen but in case you don't check the logs.

You may want to run a composer dump-auto and php artisan cache:clear  that is always a good first step when things don't work like you think they should.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Scott MadeiraCommented:
Another thing to try would be putting

dd('In the controller');

inside your index method in the welcome controller to see if it is getting that far (before you return the view.)
adra750Author Commented:
i'm sorry I didn't get you, what you mean?
adra750Author Commented:
I deleted the folder and created a new laravel project, I noticed there is index.php which leads to the first Laravel 5 welcome page, but, the weird thing is, I renamed the page to index1.php, I think laravel consider the original index.php is deleted or moved.. anyway.. After I've done that, I got the same error message: 403 Forbidden

also, /auth/register and /auth/login do not exist after the new change, No input file specified.

so why is that index.php in Public folder is important? I was trying to use views instead of public folder .. any idea?
adra750Author Commented:
the content of index

<?php
/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylorotwell@gmail.com>
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make('Illuminate\Contracts\Http\Kernel');

$response = $kernel->handle(
	$request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

Open in new window

Scott MadeiraCommented:
The index.php file in the public folder is the page/file that gets called every time you access your site.  If you look through it you can see that what it does is load up the whole Laravel application/framework into memory and starts processing your request.  That is the only php file you should have in the public folder.  First it loads the autoloader so you can find all of the classes the framework is using, then it starts up the application, then it handles the incoming request by routing it to the right controller, it sends the response to the browser and then it shuts down.

You MUST have index.php and it is a file that you will never alter as you build your site.  So, if you rename the file back to index.php does it do something?  Or, do you still get the error?
adra750Author Commented:
So If I want to change the index.php content, all i need is to add the <php .....> code inside my own index.php ?


To answer you, if I change back to index.php everything works again, once i mess with that file, then nothing works
Scott MadeiraCommented:
NEVER touch the index.php file.  Leave it just like it is.

Let's build a simple page from start to finish.  It won't do anything but display "Hello world."

1. Create a new controller called HelloController by executing the command from the root folder of your laravel installation:
php artisan make:controller HelloController  

Open in new window

This will create your controller in app/Http/Controllers.

2. Edit the controller file and in the index() method add the line  return view('hello');  All this will do is call the view specified in the file hello.blade.php And, we are done with the controller file.  The method will look like this:

public function index()
	{
		return view('hello');
	}

Open in new window


3. In the app/resources/views folder create a file called hello.blade.php and put in these contents:

<html>
<head>
    <title>My first Laravel page</title>
</head>
<body>
    <h2>Hello World!!!</h2>
</body>
</html>

Open in new window


4. We need to map a URL to that controller action so we need to edit the app/Http/routes.php file.

In that file add a line like this:

Route::resource('/hello', 'Controllers\HelloController');

Open in new window


What that will do is any URL that starts with /hello in it will route to that controller.  Because nothing is specified after the /hello, it will execute the index() method in the HelloController file.

5. You should be able to go to your site http://example.com/hello  and see Hello World! in the browser.

What Laravel does for you is this:

1. The routes file looks at the URLs coming in and figures out which controller to send the request to.
2. The controller gets the request and processes it.  It may go off to the database to get a list of users, or pull back an order requisition for processing or whatever.  It collects the data and sends that data to the view.
3. The view is compiled and merges the HTML in the view with the data from the controller to build the page that is output to the browser.
4. The complied view is sent to the browser.

The beauty of it all is that you can do all your data stuff in your controllers and get all the chunks you need.  You don't worry about how it looks on the output.  Those chunks of data are passed to a view that knows what to do to format and display the data.

I hope that helps give an idea of where everything goes.  If you can get this working then you can start to add real functions to the controllers to generate the data you want to display and then you can pass the data to the views you create to display on the screen.
adra750Author Commented:
thank you for your explanation, that is highly appreciated, but I don't want people to browse into my domain.com/ to find laravel 5 welcome page, I want to show my own index content, you see what I mean
adra750Author Commented:
When I added my html, it didn't work,

Parse error: syntax error, unexpected '<' in /home/vagrant/Code/Laravel/public/index.php on line 12


the unexpected "<" refers to the first html tag <html>


<?php
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
$response = $kernel->handle(
	$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);


<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

Open in new window


I still need to get my own index page without breaking laravel, any idea?
adra750Author Commented:
I think I figured it out, I edited the view "welcome.blade.php" and I put there my html and it works, I left index.php as it is.
adra750Author Commented:
hmmm, even though the index content is working fine, when i login it goes to /home then it says Forbidden 403...

This framework is driving me crazy :(
adra750Author Commented:
I fixed this one as well lol

it seems that laravel doesn't accept sub folders to a php file or html inside public folder
Scott MadeiraCommented:
I don't how else to say it but you can NEVER change the index.php file.  

You do all your HTML in the blade.php files in the views folder.  If you want to do subfolders in your views you can do that.  If you create a foo subfolder and have an index.blade.php file in the folder, you would call that view in your controller like this: return view('foo.index');

Not sure what you mean about your last comment and sub folders to a php file or html inside public folder...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott MadeiraCommented:
Have you looked at laracasts.com?  They have a number of tutorials and videos that cover how laravel works, how to build a site, etc.  Some of it is free.  And you can get a subscription for $9/month that is well worth at least a couple months to watch all of their content.
adra750Author Commented:
I will take a look at laracast, thank you for your patience and your efforts with me Mr Scott, that is highly appreciated, God bless you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Frameworks

From novice to tech pro — start learning today.