Laravel group route issue

Ad

I'm using this code to implement admin area routes but Route::get('/',...) doesn't work, it seems I should use anything other than / in get ,otherwise laravel doesn't load view when I browse to mysite/admin/.

Route::group(['prefix' => 'admin', 'namespace' => 'admin', 'as' => 'admin'], function() {
    Route::get('/', function() {
        return view('backend.index');
    });
    Route::resource('post', 'PostController');
});

UPDATE: there is an admin folder in public that is public/admin. It seems Laravel open this directory instead of going through the route !
is it normal ?
does public folder structure has priority to Route::get() ?

Ad

Answer

Ad

If you have admin folder inside public folder it's normal that this directory content will be displayed but it's not Laravel issue.

If you look in public/.htaccess you have there something like 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>

so if directory or file exists in public directory Laravel will not launch application but server will display this directory or this file. This is what should be done, because if there wouldn't be such rule no CSS files, JavaScript files or images could be displayed.

What you should do is either change directory name in public folder from admin to something else (and then make changes in your code to reflect this change) or change admin route to something else

Ad
source: stackoverflow.com
Ad