Normally when I call Model->save()
, it creates the new record in the database successfully. I’m trying to debug a situation when nothing happens and Model->save()
returns false. How do I find out what’s happening?
$user = new User;
$user->fields = 'example';
$user->save(); // returns false
Running this does not show any insert queries.
dd(DB::getQueryLog());
But if I var_dump($user)
, I correctly get all the fields properly saved in the object.
Thanks!
To get the insert queries when $user->save();
error, you can try to catch the exception like this:
try{
$user = new User;
$user->fields = 'example';
$user->save(); // returns false
}
catch(\Exception $e){
// do task when error
echo $e->getMessage(); // insert query
}
Hope this helps 🙂
Tags: laravel, php, phplaravel