I want to update the mail user’s with password verification and not a name verification, I can’t change the form and the method in the controller, I used the profil edit from Laravel Breeze
Model
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
Controller
public function update(ProfileUpdateRequest $request): RedirectResponse
{
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}
$request->user()->save();
return Redirect::route('dashboard')->with('status', 'profile-updated');
}
view
<form method="post" action="{{ route('profile.update') }}" class="mt-6 space-y-6">
@csrf
@method('patch')
<div class="col-span-6 sm:col-span-3">
<x-input-label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
for="email" :value="__('New email')"/>
<x-text-input id="email" name="email" type="email"
class="shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
:value="old('email', $user->email)" required autocomplete="username"/>
<x-input-error class="mt-2" :messages="$errors->get('email')"/>
@if ($user instanceof IlluminateContractsAuthMustVerifyEmail && ! $user->hasVerifiedEmail())
<div>
<p class="text-sm mt-2 text-gray-800">
{{ __('Your email address is unverified.') }}
<button form="send-verification"
class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
{{ __('Click here to re-send the verification email.') }}
</button>
</p>
@if (session('status') === 'verification-link-sent')
<p class="mt-2 font-medium text-sm text-green-600">
{{ __('A new verification link has been sent to your email address.') }}
</p>
@endif
</div>
@endif
</div>
<div class="col-span-6 sm:col-span-3">
<x-input-label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
for="name" :value="__('Name')"/>
<x-text-input id="name" name="name" type="text"
class="shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
:value="old('name', $user->name)" required autofocus autocomplete="name"/>
<x-input-error class="mt-2" :messages="$errors->get('name')"/>
</div>
I tried to update the form view with a password field instead of the name field and to add this method from the password controller in the edit email controller
$validated = $request->validateWithBag('updatePassword', [
'current_password' => ['required', 'current_password'],
'password' => ['required', Password::defaults(), 'confirmed'],
]);
$request->user()->update([
'password' => Hash::make($validated['password']),
]);