nansol
nansol

Reputation: 39

Laravel 5.4 CRUD DELETE Method not working, there is no reaction on clicking DELETE

After clicking on DELETE, there is no reaction, absolutely nothing happens. I am using HTML Forms, that's why I used, @method('DELETE'). I had similar problem with edit, after using @method(PUT), edit is working properly.

<div class="row">
    <div class="col-6 align-self-start">
        <a class="btn btn-light"  href="/listings/{{$listing->id}}/edit">Edit</a>
    </div>
    <div class="col-6 align-self-end">
        <form action="{{action('ListingsController@destroy', [$listing->id])}}" method="POST">
            <?= csrf_field()?>
            @method('DELETE')
            <a class="btn btn-danger" href="/dashboard">Delete</a>
        </form>
    </div>
</div> 

Destroy Function:

 public function destroy($id)
 {
    $listing = Listing::find($id);
    $listing->delete();
    return redirect('/dashboard')->with('success', 'Contact Deleted');
 }

Upvotes: 0

Views: 43

Answers (2)

Its recommended to use a instead of :

<button type="submit" class="btn btn-danger">Delete</button>

Upvotes: 1

Iftikhar uddin
Iftikhar uddin

Reputation: 3192

Change

<a class="btn btn-danger" href="/dashboard">Delete</a>

to

<a type="submit" class="btn btn-danger" href="/dashboard">Delete</a>

You should add submit otherwise it will not submit the form.

Upvotes: 1

Related Questions