0

Hello i am having this strange issue with laravel 5.4 is once i started i added new route admin to load dashboad view but it didn't work and instead it listed local folders inside public/admin even when i made the route return string instead of using the AdminController same result happened

Controller

    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminController extends Controller
{
   public function dashboard()
   {
       return view('admin.dashboard');
   }
}

Routes

Route::get('/', function () {
return view('welcome');
});

/*
 * Admin Routes
 */
Route::get('admin', 'AdminController@dashboard');

URL http://website.dev/admin/

The result on web page

enter image description here

Yasser Moussa
  • 2,209
  • 6
  • 26
  • 39
  • Show the route definition – Mihai Apr 08 '17 at 10:36
  • What is route definition sorry i am still new to laravel – Yasser Moussa Apr 08 '17 at 10:40
  • do you put your view files in `public/admin` ? it should be under `resources/view` instead – hassan Apr 08 '17 at 10:48
  • This seems like apache's directory listing extension result. If you using apache then you must set .htaccess correctly. – kodmanyagha Apr 08 '17 at 10:54
  • My views are under D:\xampp\htdocs\projects\pharmacy\resources\views\admin\daskboard.blade.php but even i am not reaching the point where i load the view @kodmanyagha yes i am actually using apache via XAMPP but how can i fix this problem thought .htaccess ? – Yasser Moussa Apr 08 '17 at 11:46
  • @YasserMoussa this is what your looking for - [disable directory listing](http://stackoverflow.com/questions/2530372/how-do-i-disable-directory-browsing) also make sure mod_rewrite is enabled – Gal Sisso Apr 08 '17 at 13:53
  • @Gal i did that solution by hashing line 260 in httpd.conf like that #Options Indexes FollowSymLinks Includes ExecCGI but nothing changed :( – Yasser Moussa Apr 09 '17 at 09:09
  • @YasserMoussa when you try other route names they are working fine ? – Gal Sisso Apr 09 '17 at 10:07
  • yes exactly!! when i tried new route for example adminnn it worked .. but with this particular word "admin" it didn't work i think i am missing something :-/ – Yasser Moussa Apr 09 '17 at 10:42
  • @YasserMoussa well its because you have a directory that being called 'admin'.laravel provided .htaccess file checks for folder & file existence before rewriting the url.this is how it should be,change the folder name or the route name to make this work. – Gal Sisso Apr 10 '17 at 23:19

2 Answers2

0

This seems like a .htaccess Problem, did you setup the .htaccess for the Root Directory?

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

The .htaccess must be in the Root Directory of your Project.

Another simple Approach is to rename the server.php inside the Root Directory to index.php.

You may also take a look at this Stackoverflow Question.

Community
  • 1
  • 1
  • I added .htaccess file and renamed server.php to index.php and nothing changed – Yasser Moussa Apr 09 '17 at 08:22
  • No this is my problem when i run this link i see folders from inside D:\xampp\htdocs\projects\pharmacy\public\admin .. when i should see dashbload.blade.php view is loaded :( – Yasser Moussa Apr 09 '17 at 09:46
  • This must be a Problem with your .htaccess File. What if you add "Options -Indexes" to your .htaccess? And what if you go to http://website.dev/public/index.php/admin ? – Christopher Apr 09 '17 at 11:23
0

I am pretty sure there will be a directory named admin inside your public folder to solve this problem you have to change your directory name to another name because when you hit URL host_name/admin its goes directly inside your admin folder instead of loading your public/index.php

Shailendra Gupta
  • 1,054
  • 6
  • 15