Reputation: 2506
Is there a way to make something like this?
Route::group(array('as' => 'admin', 'prefix' => 'admin', 'before' => 'admin'), function()
{
Route::get('/', array('as' => 'home', 'uses' => 'AdminController@index'));
Route::get('users', array('as' => 'users', 'uses' => 'AdminController@users'));
});
The goal is to do not include "admin" in all names and make links for above example like this:
URL::route('admin.home');
URL::route('admin.users');
Above example doesn't work:
Illegal offset type in unset
laravel/bootstrap/compiled.php:5053
Named group with nonamed routes inside works. Named routes in nonamed group work too. But not together.
Upvotes: 0
Views: 2436
Reputation: 22872
Route::group(['prefix' => 'admin', 'before' => 'adminAuth'], function(){
// If you do not want to repeat 'admin' in all route names,
// define the value here
$r = 'admin';
Route::get('users', ['as' => "{$r}.users", 'uses' => 'AdminController@users']);
Route::get('/', ['as' => "{$r}.root", 'uses' => 'AdminController@index']);
});
In yout views/redirect you can use URL::action('ControllerName@method)
and Laravel will know where redirect/point to...
Upvotes: 7