GandhyOnly
GandhyOnly

Reputation: 325

Laravel 5 Routing Object Not Found

I ussualy using Laravel 4 and now Im trying to learn Laravel 5

there's problem on Naming Controller Routes :

i had route like :

Route::get('/', [
    'uses' => 'HomeController@viewHome', 
    'as' => 'home'
]);

Route::get('/events', [
        'uses' => 'EventController@viewEvent', 
        'as' => 'event'
    ]);

when i run route as 'home' (localhost/laravel/) its work perfectly

but when i run route as 'event' (localhost/laravel/events): Object not found! enter image description here

and i already make sure that viewEvent method running right by swap it like this:

Route::get('/', [
    'uses' => 'EventController@viewEvent', 
    'as' => 'home'
]);

Route::get('/events', [
        'uses' => 'HomeController@viewHome', 
        'as' => 'event'
    ]);

i can run viewEvent but i cant run viewHome

any problem with my code?

======================== SOLVED =============================

with help @DamienPirzy and i realize when i disable /public/ folder i think i must make .htaccess out to main folder too :)

thanks all for fast response :) Problem Solved

Upvotes: 6

Views: 14631

Answers (7)

Md. Shahinur Islam
Md. Shahinur Islam

Reputation: 40

try it

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Upvotes: 0

Tayyab
Tayyab

Reputation: 11

Add index.php after project name like localhost/cms/index.php/ By doing this your all routes are working

Upvotes: 0

Vivek Sharma
Vivek Sharma

Reputation: 11

Copy the htacess file from the public folder and paste it into the root directory. It should solve the problem, also check the spelling of all routes; they must be correct.

Upvotes: 1

Rahul Tathod
Rahul Tathod

Reputation: 348

try to change .htaccess file to this

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Upvotes: 0

kamlesh.bar
kamlesh.bar

Reputation: 1804

Put this htaccess into public folder. make sure you have apache mod rewrite working.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Upvotes: 6

Tek Chansin
Tek Chansin

Reputation: 71

Could you check on .htaccess file? Cuz that screen error is from Apache. The request didn't go to Laravel App.

or check mod_rewrite is enabled,or not?

Upvotes: 2

Kornkrit Leelhaphunt
Kornkrit Leelhaphunt

Reputation: 168

i saw in routes.php

Route::get('/events', [
        'uses' => 'EventController@viewEvent', 
        'as' => 'event'
    ]);

But u run

localhost/laravel/event  

Should run

localhost/laravel/events

Upvotes: 2

Related Questions