Reputation: 934
I have a user controller which returns users list, each user belongs to different group.
ex:- $groups = ['student_users' => 1, 'teacher_users' => 2, .....]
I can create routes such as below to access them
Route::get('users/{id}', [
'as' => 'user',
'uses' => 'Admin\UserController@listUser'
]);
But i want to create more user friendly or seo friendly say like this
Route::get('users/student', [
'as' => 'student',
'uses' => 'Admin\UserController@listUser'
]);
Route::get('users/teacher', [
'as' => 'teacher',
'uses' => 'Admin\UserController@listUser'
]);
Route::get('users', [
'as' => 'student',
'uses' => 'Admin\UserController@listUser'
]);//by default shows students list.
And i want to pass the id via route not via url. Whats the best way to do it.
Upvotes: 4
Views: 3741
Reputation: 10300
do as following
Route::get('users/student', [
'as' => 'student',
'type' => 'student',
'uses' => 'Admin\UserController@listUser'
]);
in controller you can get type
as below
public function listUser(\Illuminate\Http\Request $request)
$action = $request->route()->getAction();
dd($action['type']);
}
type
is just an example. You can pass any variable.
I hope it helps.
Upvotes: 9