change email

 Create a profile page, including a form that makes a PUT request to a profile endpoint:

Route::get('profile', [ProfileController::class, 'show'])->name('profile.show');
Route::put('profile', [ProfileController::class, 'update'])->name('profile.update');
// ProfileController

public function show()
{
	return view('profile', ['user' => auth()->user()]);
}

public function update(Request $request)
{
	$validatedData = $request->validate([
		'email' => ['required', Rule::unique('users')->ignore(auth()->id())],
		// other validation rules
	]);

	auth()->user()->update($validatedData);

	return back();
}
// resources/views/profile.blade.php

<form action="{{ route('profile.update') }}" method="POST">
	@csrf
	@method('PUT')
	<input name="email" value="{{ $user->email }}">
	<!-- other profile fields -->
	<button type="submit">Update</button>
</form>

Post a Comment

أحدث أقدم