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 a primary key, set it in your model with
protected $primaryKey = '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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With