atishrajput's avatar

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

0 likes
9 replies
D9705996's avatar

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);
    }
atishrajput's avatar

yes did but nothing works. i have already mentioned its working with default parameter. so your question is invalid

D9705996's avatar

@ATISHRAJPUT - Can you please provide the full error message you are getting (please wrap the code in ``` blocks so it is correctly formatted)

gazd1977's avatar

Are you missing a set of [], looking at the docs it shows the following

Route::group(['middleware' => ['web']], function () {
    //
});
atishrajput's avatar

Route

Route::group(['middleware'=> 'CheckAge:test'], function() { Route::get('welcome', function() { echo 'Atish Kumar'; }); });

tried both way array and non array but nothing works

D9705996's avatar

@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 or to participate in this conversation.