Closed
Description
- Laravel Version: 5.7.13
- PHP Version: 7.3.1
- Database Driver & Version: mysql Ver 15.1 Distrib 10.3.12-MariaDB
Description:
in Illuminate/Database/Eloquent/Model.php
if we take a look at the fresh
method we find this at the beginning:
if (! $this->exists) {
return;
}
which mean if the model is no longer there we just return (null
?).
but the behavior of the refresh
method is slightly different:
if (! $this->exists) {
return $this;
}
in other terms, if we delete the model, and we execute the fresh()
method on it, we will get null
, but if we execute refresh()
we will get the model back again, which, if I understand correctly, is not the intended goal of this method.
Steps To Reproduce:
>>> $user = User::first()
[!] Aliasing 'User' to 'App\User' for this Tinker session.
=> App\User {#2919
id: 3,
name: "Sienna Becker",
email: "cbrekke@example.net",
email_verified_at: "2018-11-16 06:21:34",
created_at: "2018-11-16 06:21:34",
updated_at: "2018-11-16 06:21:34",
}
>>> $user->delete()
=> true
>>> $user->fresh()
=> null
>>> $user->refresh()
=> App\User {#2919
id: 3,
name: "Sienna Becker",
email: "cbrekke@example.net",
email_verified_at: "2018-11-16 06:21:34",
created_at: "2018-11-16 06:21:34",
updated_at: "2018-11-16 06:21:34",
}
>>>
if someone could confirm that this is a bug I'll send a MR for it
Metadata
Metadata
Assignees
Labels
No labels