What am trying to do is to build a laravel axios routes which have query parameters that is
a sample request looks like
axios.get("/user-management/permissions?role=" + this.role)
so the aboe generates
localhost:8000/user-management/permissions?role=admin"//role value changes
Now am stuck at setting the actual routes in the laravel routes
I have the following
Route::get('permissions/{role}', "PermissionsController@PermissionRole");
THe above route is never executed.How do i go about setting up my laravel routes to have the query string parameter
I think you misunderstood:
The route Route::get('permissions/{role}', "PermissionsController@PermissionRole");
will respond to requests of the form /user-management/permissions/admin
You don't need to specify the expected query string. You need to have this route:
Route::get('permissions', "PermissionsController@PermissionRole");
Then in your controller:
function PermissionRole(Request $request) {
$role= $request->get("role"); //admin ?
}
If you want to add the role as part of the URL you can do:
Route::get('permissions/{role}', "PermissionsController@PermissionRole");
Then you can access the role in the action:
function PermissionRole(Request $request, $role) {
//$role variable name matches the route name
}
However you can also make it mandatory by using validation:
function PermissionRole(Request $request) {
$this->validate($request->all(), [
"role" => "required|in:admin,user" //example
]);
}
route:
Route::get('permissions/{role}', "PermissionsController@PermissionRole");
Is never executed because you should have link like this:
localhost:8000/user-management/permissions/admin //admin is role