You can pass arguments to your middleware for specific routes by appending ':' followed by the value. For example, I'm enforcing different authentication methods based on the route using a single middleware.
1Route::get('...')->middleware('auth.license');2Route::get('...')->middleware('auth.license:bearer');3Route::get('...')->middleware('auth.license:basic');
1class VerifyLicense 2{ 3 public function handle(Request $request, Closure $next, $type = null) 4 { 5 $licenseKey = match ($type) { 6 'basic' => $request->getPassword(), 7 'bearer' => $request->bearerToken(), 8 default => $request->get('key') 9 };10 11 // Verify license and return response based on the authentication type12 }13}
Tip given by @Philo01