Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel debugging 404 routes

Ok, the full routes.php file that I use... I just pasted it here: http://pastebin.com/kaCP3NwK

routes.php

//The route group for all other requests needs to validate admin, model, and add assets
Route::group(array('before' => 'validate_admin|validate_model'), function()
{
    //Model Index
    Route::get('admin/(:any)', array(
        'as' => 'admin_index',
        'uses' => 'admin@index'
    ));

administrator config:

...
'models' => array(
'news' => array(
    'title' => 'News',
    'single' => 'news',
    'model' => 'AdminModels\\News',
),
...

links generator:

@foreach (Config::get('administrator.models') as $key => $model)
    @if (Admin\Libraries\ModelHelper::checkPermission($key))
        <?php $key = is_numeric($key) ? $model : $key; ?>
        <li>
            {{ HTML::link(URL::to_route('admin_index', array($key)), $model['title']) }}
        </li>
    @endif
@endforeach

controllers/admin.php

public function action_index($modelName)
{
    //first we get the data model
    $model = ModelHelper::getModelInstance($modelName);

    $view = View::make("admin.index",
        array(
            "modelName" => $modelName,
        )
    );

    //set the layout content and title
    $this->layout->modelName = $modelName;
    $this->layout->content = $view;
}

So, when accessing http://example.com/admin/news the news is sent to action_index... but for some reason it doesn't get there and it returns 404

like image 667
Alex Avatar asked Jan 04 '13 15:01

Alex


People also ask

How to debug 404 error in Laravel?

This error usually means that Laravel was not able to find the controller, controller method or a 404 error was thrown by your custom code. Some common steps to debug these would be to confirm that the route, controller, and method exist. If they all exist, then check to see if your code is throwing a 404 error.

How can I solve this 404 Not Found error even when Route exist?

Here are some ways you can try to resolve a 404 error: Double-check the URL you've entered, especially if you typed it by hand. Refresh the webpage. Use Google (or a similar search engine) to try and find the page again.

How do I change to 404 in laravel?

You need to create blade views for error pages, move to this path resources/views/ inside here create errors folder and within the directory create 404. blade. php file. It will redirect you to the 404 page if you don't find the associated URL.

What is debugging in laravel?

One of the often-used queries is Laravel Debug. It is an application, which is a part of the Laravel Framework, that helps the developer to keep a tab on the errors and bugs that may appear during the development phase. It is a handy tool since it points out the errors while the application is being developed.


2 Answers

Notice that I defined the following 'model' => 'AdminModels\\News',

when actually my namespace register was Admin\Models, so setting it to 'model' => 'Admin\Models\\News', for my issue for the 404

like image 103
Alex Avatar answered Oct 05 '22 19:10

Alex


Routes are evaluated in the order that they're registered, so the (:any) route should be last. You're being sent (I think) to admin@index -- if that function isn't defined yet, that's why you're getting a 404.

like image 35
J.T. Grimes Avatar answered Oct 05 '22 18:10

J.T. Grimes