udoyen udoyen - 11 months ago 47
PHP Question

Directory listing shown rather than view when http request is made in laravel 5.3

I new to laravel and currently building an

. Now in the application I want to get to the
admin index page
via this route: /admin
but I end up


this shows the directory content for admin folder

rather than

which should give me a view in the browser


I have added an
file with the following code in it,

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

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]

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

But it changes nothing.

Here is my

Route::get('admin', ['as'=>'posts.home', 'uses' => 'AdminPostsController@home']);

And my controller code:

public function home(){
return view('admin.index');

Please note: I initial used a simple code such as:

Rout::get('/admin', function(){ return view('admin.index'});

But I still got the same problem, but accessing the views via
route resource
works fine. Perhaps there's a
standard way
of accessing views in `laravel 5.3'.

This app is on my linux computer.

Answer Source

I am 99% sure the problem is that in your project you have a directory in your public directory that is named 'admin'. If you do, this almost certainly causes the problem, because Laravel finds the public dir and does not continue on to look for an endpoint under the same path in your routes.

Now, assuming that this really is your problem, what you have to do is either somehow change the directory structure, or change the name of your route.

First solution

Move directory public/admin to public/assets/admin

Second solution


Route::get('admin', ['as'=>'posts.home', 'uses' => 'AdminPostsController@home']);


Route::get('administration', ['as'=>'posts.home', 'uses' => 'AdminPostsController@home']);

Please let me know if that was your problem :)