简体   繁体   English

Laravel 中间件出现错误“arguments 太少无法运行”

[英]Laravel Middleware getting error 'Too few arguments to function'

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.这样他们就以 0 的入职值开始流程,一旦完成所有步骤,入职值将为 4。下面你可以看到我当前的中间件和 web.php 次尝试。

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: 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不确定我做错了什么,但这是我第一次接触 PHP 中的中间件,所以假设我犯了一个非常愚蠢的错误,因此非常感谢任何帮助

Why ara so many return $next($request);为什么这么多return $next($request); on handle在手柄上

// For a route with the following URI: profile/{id} // 对于具有以下 URI 的路由:profile/{id}

return redirect()->route('profile', ['id' => 1]);

https://laravel.com/docs/9.x/redirects#redirecting-named-routes https://laravel.com/docs/9.x/redirects#redirecting-named-routes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM