mercredi 1 août 2018

Laravel 5.6 distribute routes by user params

In the routes app/routes/web.php I have a group with a bunch of routes for resources:

Route::group(['middleware' => 'auth'], function()
{
   Route::get('/points', 'PagesController@points');
   Route::get('/users', 'PagesController@users');
   Route::get('/users/groups', 'PagesController@user_groups');
   Route::resource('point', 'PointController');
   Route::resource('user', 'UserController');
   Route::resource('users/group', 'UserGroupController');
});

Auth::routes();

Route::get('/logout', 'Auth\LoginController@logout')->name('logout');

And now I want to distribute routes in this group by user parameter:

$access = UserGroup::find( auth()->user()->group_id )->access

Route::group(['middleware' => 'auth'], function()
{
   if ($access == 1) {
      Route::get('/points', 'PagesController@points');
      Route::get('/users', 'PagesController@users');
      Route::get('/users/groups', 'PagesController@user_groups');
      Route::resource('point', 'PointController');
      Route::resource('user', 'UserController');
      Route::resource('users/group', 'UserGroupController');
   }
});

But I can't get user params right in the Route::group

How to include UserGroup model in app/routes/web.php and select access value in the Route::group?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire