I'm using laravel to create a small app. This app uses a remote database. This database doesn't have an AI id. So when I try to delete a row from the datbase (which I selected with the 'where::' function) I get the following error:
Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: delete from `mailbox` where `id` is null)
Is there a possibility to delete a row with using another key than the primary id?
If you have primary key, set in your model with
public $primary = 'my_PK';
If you don't have any PK, use a custom query:
$q = 'DELETE FROM my_table where my_field = ?'
\DB::delete($q, [$my_data]);
If you have a Model for your table, you can use something like:
Model::where('column', $value)->delete();
Where Model
is the name of your model, etc. You don't need to write the entire query yourself. You can Eloquent to make the delete query as complex as you need (i.e. multiple where
queries).