unable to navigate in laravel using route

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

unable to navigate in laravel using route

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: unable to navigate in laravel using route

Post by Celauran »

What about if you use view() in your controller method rather than View::make? Anything in your error logs?
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: unable to navigate in laravel using route

Post 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?
Last edited by publicGenome on Wed Oct 28, 2015 3:18 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: unable to navigate in laravel using route

Post by Celauran »

Start by fixing the syntax error in your routes file, then we can progress from there.
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: unable to navigate in laravel using route

Post 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.
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: unable to navigate in laravel using route

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: unable to navigate in laravel using route

Post by Celauran »

You should set your document root to the public directory. You shouldn't need /public/ in your URI
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: unable to navigate in laravel using route

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: unable to navigate in laravel using route

Post by Celauran »

I create a virtual host for each project and specify the document root in the vhost definition.
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: unable to navigate in laravel using route

Post 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. :)
Swhite
Forum Newbie
Posts: 7
Joined: Thu Feb 04, 2016 1:19 am

Re: unable to navigate in laravel using route

Post by Swhite »

Hey,
Change your config to the following:

<Directory /var/www/laravel/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
publicGenome
Forum Contributor
Posts: 110
Joined: Thu Apr 16, 2015 7:55 am

Re: unable to navigate in laravel using route

Post 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.
Post Reply