6

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

GandhyOnly
  • 325
  • 2
  • 5
  • 18

7 Answers7

6

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>
kamlesh.bar
  • 1,774
  • 19
  • 38
  • tried to add rewrite rule in this code but gives me "Object not found" https://stackoverflow.com/questions/57783056/https-laravel-using-htaccess-public – Pablo Sep 04 '19 at 07:24
2

i saw in routes.php

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

But u run

localhost/laravel/event  

Should run

localhost/laravel/events
2

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?

1

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.

Gnqz
  • 3,292
  • 3
  • 25
  • 35
0

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>
ArK
  • 20,698
  • 67
  • 109
  • 136
Rahul Tathod
  • 348
  • 5
  • 12
0

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

Tayyab
  • 11
  • 1
0

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>