RoleMiddleware
public function handle(Request $request, Closure $next, ...$role)
{
if(auth()->check() && auth()->user()->hasRole(...$role))
return $next($request);
else
return response()->redirectToRoute('login');
}
Модель пользователя User.php
public function hasRole(... $roles) {
foreach ($roles as $role) {
if ($this->roles->contains('slug', $role)) {
return true;
}
}
return false;
}
web.php
Route::get('/certificate/{user}/{group}', [StudentsController::class, 'showDataForCertificate'])->middleware(['middleware' => 'role:super-admin,co'])->name('certificate_data');
Только вместо slug, id используй