Page 1 of 1

unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 2:53 pm
by publicGenome
Hi Members,

I'm learning laravel, and having some initial hiccups with it. I've no prior experience with web development. :( Kindly bear with me.
Laravel Framework version 5.1.19 (LTS)

I created a controller as:
php artisan make:controller aboutController --plain
I can see aboutController in Http->Controller folder

In the routes.php, I write as:

Code: Select all


Route::get('about', 'aboutController@index');
That is, aboutController and use index method.

My index in aboutControllers looks like:

Code: Select all


	public function index(){
		return View::make('frontpages.about');
//return "hello"; -->nothing works
	}

I've frontpages folder in resources->views. Frontpages folder has about.blade.php present.

If I do not call any controller, and simply put it as:

Code: Select all

Route::get ('about',function(){
    return view('frontpages.about');
});
This code works perfectly fine.

If I change routes code to:

Code: Select all


Route::get('about', array ('uses'=>'aboutController@index'));
, this again doesn't help me.


I'm unable to echo anything as I'm directed to 404 page.

1- How do I fix this?
2- How do write to laravel log present in storage->logs -> laravel.log ?

Please guide.

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 3:10 pm
by Celauran
What about if you use view() in your controller method rather than View::make? Anything in your error logs?

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 3:16 pm
by publicGenome
Celauran wrote:What about if you use view() in your controller method rather than View::make? Anything in your error logs?
Hi Celauran,
Thanks for your reply.

It didn't work, I made:

Code: Select all

	public function index(){
		//return View::make('frontpages.about');
		return view('frontpages.about');
	}
Nothing I can see in laravel.log, last entry I'm able to see as:
[2015-10-14 16:11:13]
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'syntax error, unexpected '}'' in /Users/username/Sites/test_laravel/app/Http/routes.php:22
Stack trace:
Can I know if the controller is being called or not? How, and where can I track it?

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 3:17 pm
by Celauran
Start by fixing the syntax error in your routes file, then we can progress from there.

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 3:23 pm
by publicGenome
Hi,

Thanks for your reply.

I've nothing much in routes file:

Code: Select all

Route::get('/', function () {
		return view('frontpages.greet');
});

Route::get('about', array ('uses'=>'aboutController@index'));


I commented out the default welcome page re-direction.

I get error as:
The requested URL /test_laravel/about was not found on this server.

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 3:30 pm
by publicGenome
Update:

I got it working.

I had to type public to get to index/home page of laravel. Thus, initially, I moved index.php from public to root folder, and skipped typing public in the URL.

With changes as:

Code: Select all

require __DIR__.'/../bootstrap/autoload.php'; //this is changed when the index file moved
//require __DIR__.'/bootstrap/autoload.php';


$app = require_once __DIR__.'/../bootstrap/app.php'; //this is changed when the index file moved
//$app = require_once __DIR__.'/bootstrap/app.php';

After this I didn't have to type public in the URL.
When I moved this index.php back to its original location routes.php is taking me to the about page. Route seems to work.

But every time I've to add public to get this working, to avoid this, I had moved the index files. I found this option to edit index file.
I think I should go with editing of vhosts that would be much better, without disrupting the entire set up.

Thanks.

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 3:33 pm
by Celauran
You should set your document root to the public directory. You shouldn't need /public/ in your URI

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 3:36 pm
by publicGenome
Celauran wrote:You should set your document root to the public directory. You shouldn't need /public/ in your URI
Hi C,
Thanks.
Is it the same as to make changes in vhost, http-extra file, or to make changes anywhere else in laravel project?

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 4:42 pm
by Celauran
I create a virtual host for each project and specify the document root in the vhost definition.

Re: unable to navigate in laravel using route

Posted: Wed Oct 28, 2015 4:59 pm
by publicGenome
Celauran wrote:I create a virtual host for each project and specify the document root in the vhost definition.
Thank you. That helps very much. :)

Re: unable to navigate in laravel using route

Posted: Mon Feb 08, 2016 6:41 am
by Swhite
Hey,
Change your config to the following:

<Directory /var/www/laravel/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Re: unable to navigate in laravel using route

Posted: Mon Feb 08, 2016 7:15 am
by publicGenome
Swhite wrote:Hey,
Change your config to the following:

<Directory /var/www/laravel/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Hi Swhite,
Thank you for your reply. :) I'll look into this.