Monday, May 22, 2017

Method spoofing not working laravel

I have a form associated with destroy method to delete a item/record:

<form action="" method="POST">
        <input type="hidden" name="_method" value="DELETE">
        <input type="hidden" name="_token" value="">
        <button type="submit" class="btn btn-danger btn-sm">
            <i class="fa fa-trash-o" aria-hidden="true"></i> Delete
        </button>
</form>

And my code in destroy method is:

public function destroy(Cexcluded $cexcluded)
{
    $cexcluded->tours()->detach();
    $cexcluded ->delete();
    Session::flash('success','Item sucessfully deleted !');
    return redirect()->route('climb.ie');
}

And my routes are:

 Route::resource('climb-excluded','CexcludedsController',
['only'=>['store','destroy']]);
 Route::get('climbing/included-excluded','HomeController@getclimbIE')
->name('climb.ie');  

The trouble I'm having is the destroy method is not deleting the record from DB and doesn't give any error. It is giving session message without deleting the record.



via Tanja Forsberg

Advertisement