Error in laravel 5.7 Unable to pass the parameter to laravel middleware group. getting error Class doesn't exists but working with default or without default parameter.
Route
Route::group(['middleware'=> 'CheckAge:test'], function() {
Route::get('welcome', function() {
echo 'Atish Kumar';
});
});
File - CheckAge.php
Have you registered your middleware and ensured you are passing the variable to the handle function of your middleware?
public function handle($request, Closure $next, $age)
{
if ($age !== 'test') {
// Redirect...
}
return $next($request);
}
yes did but nothing works. i have already mentioned its working with default parameter. so your question is invalid
@ATISHRAJPUT - Can you please provide the full error message you are getting (please wrap the code in ``` blocks so it is correctly formatted)
Are you missing a set of [], looking at the docs it shows the following
Route::group(['middleware' => ['web']], function () {
//
});
tried everything but nothing works
Route
Route::group(['middleware'=> 'CheckAge:test'], function() {
Route::get('welcome', function() {
echo 'Atish Kumar';
});
});
tried both way array and non array but nothing works
@ROBSTAR - yes its exactly like as the docs
@ATISHRAJPUT - Are you able to provide the exact error message you are getting. It might help us identify your problem. Can you also share your middleware class and how you have registered it
Please sign in or create an account to participate in this conversation.