0
votes

When I click delete button its show that error. I can't find out the problem.

route.php

 Route::post('api/email/create', ['as' => 'email.create', 'uses' => 'Havence\AutoMailController@create']);
    Route::get('automail/mail',['as'=>'email.mail','uses' => 'Havence\AutoMailController@mail']);
    Route::get('automail/index',['as'=>'email.index','uses' => 'Havence\AutoMailController@index']);
    Route::get('automail/edit/{id}',['as'=>'email.edit','uses' => 'Havence\AutoMailController@edit']);
    Route::post('automail/delete/{id}',['as'=>'email.delete','uses' => 'Havence\AutoMailController@destroy']);

delete button function

  <form  data-toggle="tooltip" title="Delete Template" data-placement="top" action="{{ route('email.delete', $mailTemplate->id) }}" method="POST">
    {{csrf_field()}}
    <input name="_method" type="hidden" value="DELETE">
    <button  type="submit" class="imgb col-md-3 text-center p-2"><img src="https://img.icons8.com/nolan/40/delete-forever.png" ></button>
</form>

controller

 public function destroy($id)
    {
        $mailTemplates = Ticket::find($id);
        $mailTemplates->delete();

        return redirect('/index')->with('success', 'Ticket has been deleted!!');

    }
1
Could you provide working example that reproduce error. Git or example working project. Could be simplified and without private data.SkorpEN

1 Answers

0
votes

change this beacuse you are passing hidden _method

Route::post('automail/delete/{id}',['as'=>'email.delete','uses' => 'Havence\AutoMailController@destroy']);

to

Route::delete('automail/delete/{id}',['as'=>'email.delete','uses' => 'Havence\AutoMailController@destroy']);