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?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kJD5bP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire