我试图为我的网站做一个入职部分。但是当我试图实现我的中间件时,我得到了以下错误。
我正在尝试在用户每次完成一个登录过程的时候分配一个不同的登录值来完成我的登录过程。这样他们就可以从一个0的登录值开始这个过程,而一旦所有的步骤都完成了,登录值将是4。下面你可以看到我当前的中间件和web.php尝试。
中间件:
class OnBoarding
{
public function handle(Request $request, Closure $next, User $user)
{
if (! Auth::check()) {
return redirect()->route('login');
}
return $next($request);
if (Auth::user()->onboarded == 0) {
return redirect()->route('employment.index', $user);
}
return $next($request);
if (Auth::user()->onboarded == 1) {
return redirect()->route('qualificationsAndCertifications.index', $user);
}
return $next($request);
if (Auth::user()->onboarded == 2) {
return redirect()->route('extraDocs.index', $user);
}
return $next($request);
if (Auth::user()->onboarded == 3) {
return redirect()->route('additionalInformation.index', $user);
}
return $next($request);
if (Auth::user()->onboarded == 4) {
return redirect()->route('dashboard.index');
}
return $next($request);
}
}
网页. php:
Route::middleware('auth','verified','onboarded')->group(function () {
Route::get('/onboarding/employment/{user}', [UserController::class , 'employment'])- >name('employment.index');
Route::get('/onboarding/additional-information/{user}', [UserController::class , 'additionalInformation'])->name('additionalInformation.index');
Route::get('/onboarding/certification/{user}', [UserController::class , 'qualificationsAndCertifications'])
->name('qualificationsAndCertifications.index');
Route::get('/onboarding/certification/extra/{user}', [UserController::class , 'extraDocs'])->name('extraDocs.index');
不知道我做错了什么,但这是我第一次接触PHP中间件,所以假设我犯了一个非常愚蠢的错误,因此任何帮助将不胜感激
1条答案
按热度按时间jv4diomz1#
为什么手柄上有这么多
return $next($request);
//对于具有以下URI的路由:配置文件/{id}
https://laravel.com/docs/9.x/redirects#redirecting-named-routes