【问题标题】:Laravel - Missing required parameters for [Route: reset-password.index]Laravel - 缺少 [Route: reset-password.index] 所需的参数
【发布时间】:2021-08-17 16:32:58
【问题描述】:

我只是 Laravel 的新手,所以在这样的现成项目上工作仍然不是很好, 无论如何,当用户尝试重置密码时,它会失败显示:

~/public_html$ php artisan queue:work
[2021-05-29 19:52:02][182577] Processing: App\Mail\Core\ResetPassword
[2021-05-29 19:52:02][182577] Failed:     App\Mail\Core\ResetPassword

当我检查日志文件时,我发现了这个错误:

[previous exception] [object] (Illuminate\\Routing\\Exceptions\\UrlGenerationException(code: 0): Missing required parameters for [Route: reset-password.index] [URI: reset-password/{user}]. at /home/user/public_html/vendor/laravel/framework/src/Illuminate/Routing/Exceptions/UrlGenerationException.php:17)

作为一个新手,我不知道该怎么做,搜索了很多但没有机会。

这是我的路线:

 Route::get('reset-password/{user}', [AuthController::class, 'resetPassword'])
   28:     ->name('reset-password.index');
   29: Route::post('reset-password/{user}/update', [AuthController::class, 'updatePassword'])
   30:     ->name('reset-password.update');

这是我的 URI:

@component('mail::button', ['url' => url()->temporarySignedRoute('reset-password.index', now()->addMinutes(30), ['id' => $user->id])])
    {{ __('Reset Password') }}
@endcomponent

这是我的来自 AuthController 的 resetPassword 函数:

 public function resetPassword(Request $request, User $user): View
    {
        $data = $this->service->resetPassword($request, $user->id);

        return view('core.no_header_pages.reset_password', $data);
    }

这是我的 resetPassword @ Services:

public function resetPassword(Request $request, $id)
{
    abort_unless($request->hasValidSignature(), 401, 'Invalid Request.');

    $passwordResetLink = url()->signedRoute('reset-password.update', ['user' => $id]);

    return [
        'id' => $id,
        'passwordResetLink' => $passwordResetLink
    ];
}

有机会吗?

【问题讨论】:

    标签: php laravel routes laravel-8


    【解决方案1】:

    您的reset-password 路由参数是user,但您在组件中使用id。换成user

    @component('mail::button', [
        'url' => url()->temporarySignedRoute('reset-password.index', now()->addMinutes(30),
        ['user' => $user->id])]) // passing an id but with a named parameter of `user`
        {{ __('Reset Password') }}
    @endcomponent
    

    【讨论】:

    • 完成...非常感谢 =) 我会在 6 分钟 (Y) 后接受答复
    • @BurhamB.Soliman 不用担心,小事有时很容易被忽视。 :)
    • 我的日志中有另一个错误,请您帮我解决一下吗?
    • [2021-05-29 21:04:44] production.ERROR: 提供的 cwd "" 不存在。 {"exception":"[object] (Symfony\\Component\\Process\\Exception\\RuntimeException(code: 0): 提供的 cwd \"\" 不存在。在 /home/user/public_html/vendor/ symfony/process/Process.php:344) 抱歉惹恼了,但我有很多这样的错误,有什么线索吗?
    • @BurhamB.Soliman 我怀疑它与您正在执行的命令有关,但除此之外我不确定。 cwd 是一个用于返回 current working directory 的 linux 命令,它似乎在该错误消息中返回空。
    猜你喜欢
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 2021-11-06
    相关资源
    最近更新 更多