Controller MessagesController:

public function destroy(Messages $message) { $message->delete(); return redirect()->route('messages.index')->with('message', 'Запись удалена.'); } 

routes.php:

 Route::resource('messages', 'MessagesController@index'); Route::post('messages.store', ['as' => 'messages.store', 'uses' => 'MessagesController@store']); Route::delete('messages.destroy', ['as' => 'messages.destroy', 'uses' => 'MessagesController@destroy']); 

View page:

  {!! Form::open(array('route'=>['messages.destroy',$message->id],'method'=>'DELETE')) !!} {!! Form::button('Удалить',['class'=>'btn btn-danger','type'=>'submit']) !!} {!! Form::close() !!} 

When you click on the button, a message about deletion is displayed, but this does not happen. It is still displayed on the view page.

  • Try to delete at first without deppendance of an injection, $ id, $ message = Message :: find ($ id) -> delete (); - Orange_shadow
  • It was not necessary to call the active record in the plural. And if you have a Collection class in Messages , you must pass at least $id - vp_arth into delete

1 answer 1

First, look with the help of print_r or var_dump request $ request is there a message id variable.

 use App\Messagges; //загрузка модели сообщения public function destroy(Request $post) { $messagge=new Messagges; $messagge::find($post['id_messagge']); //сначала находим $messagge->delete(); //затем удаляем. return redirect()->route('messages.index')->with('message', 'Запись удалена.'); }