Filth's avatar

Route not loading View

Im new to Laravel so im sure there is something dead simple im missing here..

I have started setting up the "front end" of my app fine, I have now moved on to the admin area. To do this I have created admin.blade.php in the views folder. Within view is another folder called admin which contains the admin pages.

Take admin/dashboard.blade.php, I have

@extends('admin')

on first line, also have

DashboardController@index which contains

return view('admin.dashboard');

the Routes file has:

Route::get('admin', 'DashboardController@index');

when I visit my app url/admin i get a page not found.

0 likes
18 replies
Filth's avatar
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class DashboardController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('admin.dashboard');
    }
TahiriAbdou's avatar

you must be mistaken something , And how does your views look ? maybe you should try to see the view first on a closure then go to controller.

Route::get('admin',function(){
    return view('admin.dashboard');
});
stefanbauer's avatar

As the page could not be found, it doesn't have to do anything with your view... just return anything in the specific route to verify that the route is working fine. Something like

Route::get('admin', function() { return 'something'; });

Try it again. If your route is working, then there is a problem with your mapping to the controller and the method. If not you have a routing problem. If it is so, show us the routes.php. I never used your syntax above. I always use that syntax:

Route::get('admin', ['uses' => 'DashboardController@index']);

Maybe try that. If that doesn't work, please paste the full trace of the error.

Filth's avatar
Route::get('admin', function() { return 'something'; });

also returns page not found so it is a route issue, below is my routes.php

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', 'Pages\FrontendController@index');



// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

Route::get('admin', function() { return 'something'; });

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

Route::get('articles', 'ArticlesController@index');
Route::get('articles/{slug}', 'ArticlesController@show');

Route::get('anglers', 'AnglersController@index');

Route::get('videos', 'VideosController@index');

Route::get('videos/{slug}', 'VideosController@show');

Route::controllers([
   'password' => 'Auth\PasswordController',
]);
Filth's avatar

If i rename the route to any other word, it works, for some reason admin wont? is it possible it conflicts with admin.blade.php?

Filth's avatar
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
| Domain | Method                         | URI                                                   | Name | Action                                                     | Middleware |
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
|        | GET|HEAD                       | /                                                     |      | App\Http\Controllers\Pages\FrontendController@index        |            |
|        | GET|HEAD                       | admin                                                 |      | Closure                                                    |            |
|        | GET|HEAD                       | anglers                                               |      | App\Http\Controllers\AnglersController@index               |            |
|        | GET|HEAD                       | articles                                              |      | App\Http\Controllers\ArticlesController@index              |            |
|        | GET|HEAD                       | articles/{slug}                                       |      | App\Http\Controllers\ArticlesController@show               |            |
|        | POST                           | auth/login                                            |      | App\Http\Controllers\Auth\AuthController@postLogin         | guest      |
|        | GET|HEAD                       | auth/login                                            |      | App\Http\Controllers\Auth\AuthController@getLogin          | guest      |
|        | GET|HEAD                       | auth/logout                                           |      | App\Http\Controllers\Auth\AuthController@getLogout         |            |
|        | GET|HEAD                       | auth/register                                         |      | App\Http\Controllers\Auth\AuthController@getRegister       | guest      |
|        | POST                           | auth/register                                         |      | App\Http\Controllers\Auth\AuthController@postRegister      | guest      |
|        | POST                           | password/email/{one?}/{two?}/{three?}/{four?}/{five?} |      | App\Http\Controllers\Auth\PasswordController@postEmail     | guest      |
|        | GET|HEAD                       | password/email/{one?}/{two?}/{three?}/{four?}/{five?} |      | App\Http\Controllers\Auth\PasswordController@getEmail      | guest      |
|        | POST                           | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} |      | App\Http\Controllers\Auth\PasswordController@postReset     | guest      |
|        | GET|HEAD                       | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} |      | App\Http\Controllers\Auth\PasswordController@getReset      | guest      |
|        | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing}                                   |      | App\Http\Controllers\Auth\PasswordController@missingMethod | guest      |
|        | GET|HEAD                       | videos                                                |      | App\Http\Controllers\VideosController@index                |            |
|        | GET|HEAD                       | videos/{slug}                                         |      | App\Http\Controllers\VideosController@show                 |            |
+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+
TahiriAbdou's avatar

i think its a server problem, how do you launch your laravel application ? may be you could try this :

    php artisan serve 

you can try to access to your application with this url http://127.0.0.1:8000

stefanbauer's avatar

I am not sure. Your routes look fine. I tested it here with same Closure (L5.1), no problems. Working as expected. I don't think that it has something to do with your blade. In any case the Closure has to work.

1 like
Filth's avatar

@TahiriAbdou visiting http://127.0.0.1:8000 after that artisan command returns an unable to connect error.

My development server runs off a synology NAS, I work on a macbook with the volume mounted. my app config has the url set to:

http://10.0.0.4/app_laravel/public

and I use that url in a browser to view my project.

Its strange that if i use any word other 'admin' the route works...

TahiriAbdou's avatar

Create a .htaccess file your Laravel root directory if it does not exists already. (Normally it is under your public_html folder) add the following code :

    <IfModule mod_rewrite.c>
         RewriteEngine On 
        RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
thomaskim's avatar
Level 41

@Philwn Make sure you do not have an admin folder inside your public directory. If you do, then rename the route URI or rename the folder to something else. The route URI and the public directory should not match.

1 like
Filth's avatar

It wont work, for my local development server I need to have /public in. Obviously this wouldnt be the case when live.

Filth's avatar

Turns out it is a simple error on my behalf, there is a folder in public called admin which stores admin specific css plugins etc. So it is porbably safe to say that was causing the issue!

Thank you for everyones time on this

Filth's avatar

@thomaskim I missed your answer sorry, I came across this being the issue this morning and realised so updated the thread here with my answer, now I have seen your answer I have marked that as the correct answer as you pointed it out first.

Thank You for everyones time on an issue which was simply my own fault!

Please or to participate in this conversation.