-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
Laravel Version
10.8.0
PHP Version
8.1.17
Database Driver & Version
MariaDb 10.6
Description
When detaching, e.g.:
$ids = [...];
$user->posts()->detach($ids);
https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php#L478 is triggered, which builds a Pivot object only with pivot-key attributes (e.g. user_id and post_id). The remaining pivot attributes don't get included. This becomes a problem especially when this deleted pivot object is passed to some deleted event. Deleted object not having all its attributes causes issues where those attributes are needed. And that object being already deleted, unfortunately can't be refresh()ed.
At https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php#L513 we can see it potentially could build full pivot object if $this->pivotValues were populated. But the latter is empty.
Steps To Reproduce
Description should be enough.
