lundi 30 janvier 2017

Laravel5: Can't delete from DB

This is in controller MessagesController:

    public function destroy(Messages $id)
{
    \DB::delete(
            'DELETE FROM messages WHERE id=' . $id
        );
    return redirect()->route('messages.index')->with('message', 'Deleted.');
}

This is routes.php:

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

This is view file:

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

So, I have an error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[]' at line 1 (SQL: DELETE FROM messages WHERE id=[])

I understand that there is no id going to controller. How to solve this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire