I'm trying to make an onboarding section for my website. But while trying to implement my middleware I get the following error.
I`m trying to do my onboarding process by assigning a different onboarding value each time the user completes a section of the onboarding process. Such that they start the process with an onboarded value of 0 and once all steps are completed there onboarded value will be 4. Below you can see my current middleware and web.php attempts.
Middleware:
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);
}
}
Web.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');
Not sure what I'm doing wrong but this is my first time touching middleware in PHP so assume I'm making a really stupid mistake and therefore any help would be greatly appreciated
Why ara so many return $next($request);
on handle
// For a route with the following URI: profile/{id}
return redirect()->route('profile', ['id' => 1]);
https://laravel.com/docs/9.x/redirects#redirecting-named-routes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.