RESTful Laravel Routing

I am trying to access my url:

www.mysite.com/user/dash/sales

There is a DashboardController.php file in my controller directory:

<?php class DashboardController extends BaseController { public function __construct() { $this->beforeFilter('auth'); } /** * Supplier 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 dashboard screen * */ public function getAdmin() { $this->layout->content = View::make('user.dashboard.admin'); } } 

I tried all of the following features in the 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 am not quite sure how to make this successful route. The error message I get with all of these routes is the following:

Controller method not found.

+6
source share
1 answer

Well, after you dig a lot more and read a lot of articles, this rule is called "first, first out":

 <?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It 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, if you have a route leading to the user, but then you want to go deeper, you need to put the deepest FIRST in the routes.php file!

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

Answer: user3130415

+3
source

All Articles