6

I'm trying to access my URL at:

www.mysite.com/user/dash/sales

I have in my controllers directory, a DashboardController.php file:

<?php

class DashboardController extends BaseController {

    public function __construct() {

        $this->beforeFilter('auth');

    }

    /**
     * Supplier's dashboard screen
     *
     */
    public function getSupplier()
    {
        $this->layout->content = View::make('user.dashboard.supplier');
    }

    /**
     * Sales dashboard screen
     *
     */
    public function getSales()
    {
        $this->layout->content = View::make('user.dashboard.sales');
    }

    /**
     * Admin's dashboard screen
     *
     */
    public function getAdmin()
    {
        $this->layout->content = View::make('user.dashboard.admin');
    }

}

I've tried all the following possibilities in my routes.php file with no luck:

Route::any('user/dash/(:any)', array('uses' => 'DashboardController') );

Route::controller( 'user/dash', 'DashboardController' );

Route::group(array('prefix' => 'user', 'before' => 'auth'), function() 
{ 
    Route::controller('dash', 'DashboardController');
});

Does anyone have any other suggestions? I'm not quite sure on how to make this a successful route. The error message I get with all those routes is this:

Controller method not found.

1 Answer 1

3

Ok after a lot more digging around and reading loads of articles, there is this rule called "first in, first out":

<?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 Closure to execute when that URI is requested.
|
*/

/** RESTful Controllers **/
Route::controller( 'user/dash', 'DashboardController' );
Route::controller( 'user', 'UserController' );
Route::controller( 'product', 'ProductController' );

Route::group(array('prefix' => 'dash', 'before' => 'auth'), function()
{
    Route::controller('product', 'Dash_ProductController');
    Route::controller('user', 'Dash_UserController');
});

/** Home/Fallback Controller **/
Route::controller('/', 'HomeController');

So therefore if you have a route leading to user, but then want to go deeper, you have to put the deepest FIRST in your routes.php file!

Fantastic article read : http://laravel.io/topic/30/routes-first-in-first-out

Answered By: user3130415

Sign up to request clarification or add additional context in comments.

1 Comment

@kJamesy Here is the link from the archive, web.archive.org/web/20130912011338/http://laravel.io/topic/30/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.