samedi 29 septembre 2018

Issue with delete http method in firefox and laravel

Hi I have an issue in Laravel. I have a project in Laravel and I'm having issues in Firefox. In Chrome all is working fine. I have this admin view

@foreach ($messages as $message)
    <tr>
      <td>
      <a href="">
        
      </a>
      </td>
      <td></td>
      <td></td>
      <td></td>
      <td>
        <a class="btn btn-primary" href="">Editar</a>

        <form style="display:inline" action=" " method="post">
          {!! csrf_field() !!}
          {!! method_field('DELETE') !!}
          <button type="submit" class="btn btn-danger" name="button">Eliminar</button>
        </form>
      </td>
    </tr>

  @endforeach

I have a table with two buttons, second button is a form to delete the message. O have added method_field('DELETE')

Here is my routes.

Route::get('mensajes', 'MessagesController@index')->name('messages.index');
Route::get('mensajes/create', 'MessagesController@create')->name('messages.create');
Route::post('mensajes', 'MessagesController@store')->name('messages.store');
Route::get('mensajes/{id}', 'MessagesController@show')->name('messages.show');
Route::get('mensajes/{id}/edit', 'MessagesController@edit')->name('messages.edit');
Route::put('mensajes/{id}', 'MessagesController@update')->name('messages.update');
Route::delete('mensajes/{id}', 'MessagesController@destroy')->name('messages.destroy');

And here the MessagesController destroy method

public function destroy($id)
{
    //borro el mensaje
    //DB::table('messages')->where('id', $id)->delete();
    Message::findOrFail($id)->delete();

    //redirecciono
    return redirect()->route('messages.index');
}

In Chrome all works fine and message is deleted. But in Firefox, it redirects to /mensajes/{id} route and the message in shown. It seems in Firefox {!! method_field('DELETE') !!} is not working. Do anybody knows what I'm doing wrong?

Best regards.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire