PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Jun 24, 2019 5:32 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Wed Oct 28, 2015 2:53 pm 
Offline
Forum Contributor

Joined: Thu Apr 16, 2015 7:55 am
Posts: 110
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:
Quote:
php artisan make:controller aboutController --plain

I can see aboutController in Http->Controller folder

In the routes.php, I write as:
Syntax: [ Download ] [ Hide ]

Route::get('about', 'aboutController@index');
 

That is, aboutController and use index method.

My index in aboutControllers looks like:

Syntax: [ Download ] [ Hide ]

        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:
Syntax: [ Download ] [ Hide ]
Route::get ('about',function(){
    return view('frontpages.about');
});
 
This code works perfectly fine.

If I change routes code to:
Syntax: [ Download ] [ Hide ]

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.


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 3:10 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
What about if you use view() in your controller method rather than View::make? Anything in your error logs?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 3:16 pm 
Offline
Forum Contributor

Joined: Thu Apr 16, 2015 7:55 am
Posts: 110
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:
Syntax: [ Download ] [ Hide ]
        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:

Quote:
[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.

Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 3:17 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Start by fixing the syntax error in your routes file, then we can progress from there.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 3:23 pm 
Offline
Forum Contributor

Joined: Thu Apr 16, 2015 7:55 am
Posts: 110
Hi,

Thanks for your reply.

I've nothing much in routes file:
Syntax: [ Download ] [ Hide ]
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:
Quote:
The requested URL /test_laravel/about was not found on this server.


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 3:30 pm 
Offline
Forum Contributor

Joined: Thu Apr 16, 2015 7:55 am
Posts: 110
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:
Syntax: [ Download ] [ Hide ]
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.


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 3:33 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
You should set your document root to the public directory. You shouldn't need /public/ in your URI

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 3:36 pm 
Offline
Forum Contributor

Joined: Thu Apr 16, 2015 7:55 am
Posts: 110
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?


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 4:42 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
I create a virtual host for each project and specify the document root in the vhost definition.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Oct 28, 2015 4:59 pm 
Offline
Forum Contributor

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


Top
 Profile  
 
PostPosted: Mon Feb 08, 2016 7:41 am 
Offline
Forum Newbie

Joined: Thu Feb 04, 2016 2:19 am
Posts: 7
Hey,
Change your config to the following:

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


Top
 Profile  
 
PostPosted: Mon Feb 08, 2016 8:15 am 
Offline
Forum Contributor

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group