Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix delete button in laravel crud

I am trying to delete a record but when I press delete button it takes me to a white screen.
index.blade.php

<form>
   @csrf
   @method('DELETE')
   <button type="submit" formaction="{{ route('user.destroy',$user->id) }}">Delete</button>
</form>

Controller destroy function

public function destroy(User $user)
    {
        User::findOrfail($user->id)->delete();
        return redirect()->route('user.index')->with('success','Record Deleted Successfully!!!');
    }

Route

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Route::resource('/onemany/user',UserController::class);

Route List for the project
I am trying to delete the record. Tried using anchor tag also but getting same result with it.

>Solution :

Most probably, the problem will occur at the route name and it wont enter the controller method at all.

You could do php artisan route:list and find out the correct route name.

Edit:

                           <form action="{{ route('user.destroy',$user->id) }}" method="Post">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-danger">Delete</button>
                        </form>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading