I want to use the CRUD in my web project, I imported the starter kit breeze to have a CRUD (after the project has been created / bit too late)
Unfortunately I can’t access to the method from the controller I always get redirected to the log out method through another controller AuthenticatedSessionController which call an aother destroy method to logout.
In this case I would my view to call the Profile controller and not the Authenticated Controller and apply the CRUD method
AuthenticatedSessionController :
public function logout(Request $request): RedirectResponse
{
Auth::guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect('/');
}
ProfileController : (the one should destroy, edit, etc) :
public function edit(Request $request): View
{
return view('profile.edit', [
'user' => $request->user(),
]);
}
/**
* Update the user's profile information.
*/
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('profile.edit')->with('status', 'profile-updated');
}
public function destroy(Request $request): RedirectResponse
{
$request->validateWithBag('userDeletion', [
'password' => ['required', 'current_password'],
]);
$user = $request->user();
Auth::logout();
$user->delete();
$request->session()->invalidate();
$request->session()->regenerateToken();
return Redirect::route('/')
->with('success', __('messages.user_deleted_successfully'));
}
My route web.php
Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
// dd('124');
// Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
require __DIR__.'/auth.php';
My route auth.php
Route::post('logout', [AuthenticatedSessionController::class, 'logout'])
->name('logout');
Route::delete('/profile', [AuthenticatedSessionController::class, 'destroyUser'])->name('profile.destroy');
and my view :
<form action="{{ route('profile.destroy', auth()->user()->name) }}" method="POST">
@csrf
@method('delete')
<button type="submit" class="text-white bg-red-600 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm inline-flex items-center px-3 py-2.5 text-center mr-2 dark:focus:ring-red-900">Delete</button>
</form>