I am trying to get a record from a posts
database table using its id. I've been banging my head on the find() method for quite sometime now, confused as to why it wasn't working. Here is my query that looks correct to me but didn't work:
$post = Post::find($id);
$post->delete();
Reluctantly i did this:
$post = Post::where('id', $id);
$post->delete();
and surprisingly enough, it worked but I have no idea how.
I also know that unlike find()
, where()
is a query builder and so I could also use it like this:
Post::where('id', $id)->first()
Any ideas about the difference in the way the methods work?