如何解决Laravel 8 Jetstream / livewire让密码重置表单接受用户名而不是电子邮件
重新删除电子邮件字段并添加用户名字段非常容易。 (毕竟与 loginview 一起工作)它使用用户名字段进行身份验证就好了,我也做了同样的事情。
\resources\views\auth\reset-password.blade.PHP ```
<form method="POST" action="{{ route('password.update') }}">
@csrf
<input type="hidden" name="token" value="{{ $request->route('token') }}">
<div class="block">
<x-jet-label for="username" value="{{ __('User name') }}" />
<x-jet-input id="username" class="block mt-1 w-full" type="text" name="username" :value="old('username')" required autofocus autocomplete="username" />
</div>
{{-- <div class="block">
<x-jet-label for="email" value="{{ __('Email') }}" />
<x-jet-input id="email" class="block mt-1 w-full" type="email" name="email" :value="old('email',$request->email)" required autofocus />
</div> --}}
<div class="mt-4">
<x-jet-label for="password" value="{{ __('Password') }}" />
<x-jet-input id="password" class="block mt-1 w-full" type="password" name="password" required autocomplete="new-password" />
</div>
<div class="mt-4">
<x-jet-label for="password_confirmation" value="{{ __('Confirm Password') }}" />
<x-jet-input id="password_confirmation" class="block mt-1 w-full" type="password" name="password_confirmation" required autocomplete="new-password" />
</div>
<div class="flex items-center justify-end mt-4">
<x-jet-button>
{{ __('Reset Password') }}
</x-jet-button>
</div>
</form>
但是当我尝试使用它时,我得到:
Whoops! Something went wrong.
The email field is required.
我不知道在哪里验证输入,以便我进行所需的更改以期望用户名代替电子邮件地址。
解决方法
Jetsteam 使用 fortify 作为后端。更改config\fortify.php
/*
|--------------------------------------------------------------------------
| Username / Email
|--------------------------------------------------------------------------
|
| This value defines which model attribute should be considered as your
| application's "username" field. Typically,this might be the email
| address of the users but you are free to change this value here.
|
| Out of the box,Fortify expects forgot password and reset password
| requests to have a field named 'email'. If the application uses
| another name for the field you may define it below as needed.
|
*/
'username' => 'username',// change this to username
'email' => 'email',
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。