Laravel admin/user route prefix approach -


so have make system transport management. user can log in create/update/edit trips. admin can same users. have divided user , admin in route prefixes:

route::group(['prefix' => 'admin/', 'middleware' => ['auth','admin']], function(){ route::resource('trips', 'tripscontroller',         array('except' => array('show')));}  route::group(['prefix' => 'user/', 'middleware' => ['auth', 'user']], function(){  route::resource('trips', 'tripscontroller',         array('except' => array('show'))); } 

the problem in every method of tripcontroller have pass route variable correct url (the admin request have 'admin' prefix, , users have 'user' prefix)

return view('trips.index', compact('users', 'route')); 

the question there way nicely or should pull trips route::resource out of both groups wouldn't have groups? correct approach here?

i use approach:

route::group(['namespace' => 'admin', 'as' => 'admin::', 'prefix' => 'admin'], function() {      // other middlewares      route::group(['middleware' => 'isnotauthenticated'], function(){          // "admin::login"         // http://localhost:8000/admin/login         route::get('login', ['as' => 'login', 'uses' => 'admincontroller@index']);      });       // admin middlewares     route::group(['middleware' => 'admin'], function(){          // "admin::admin.area.index"         // http://localhost:8000/admin/area/{area}         route::resource('area', 'areacontroller');          // "admin::dashboard"                // http://localhost:8000/admin/         route::get('/', ['as' => 'dashboard', 'uses' => 'admincontroller@dashboard']);      });  }); 

whenever need access url in blade templates use route helper method.

// resourceful routes      {{ route('admin::admin.city.index') }} 

or

//for regular get/post routes   {{ route('admin::dashboard') }} 

or run artisan command list route names.

php artisan route:list 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -