Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JoewyZN's avatar

Delete record using 'WHERE'

Hi .. i am trying to delete a record, but not through the primary key.. Im doing the following ;

$picture=Picture::where("filename","=",$filename);
$picture->delete;

The record is never deleted, my assumption is that laravel will only allow the delete if I use a key instead of a normal column... What am I missing? thanks in advance #newbie

0 likes
3 replies
tonysmessias's avatar
Level 7

Try this:

Picture::where('filename', $filename)->delete();

If you have the model already in a variable, then:

$picture->delete();
3 likes
JoewyZN's avatar

tonysmessias thanks for the reply... turns out the dynamic data from Input::all(); was invalid... the function actually works !!! The error was on my part..

Please or to participate in this conversation.