@pmusa I believe you can save a temp variable yourself using the restoring event first and then use the same one in the restored even though I don't know what is wrong by using the restoring if it already works?
So in your observer add this:
private $deletedAt = null;
public function restoring(Post $post)
{
$this->deletedAt = $post->deleted_at;
...
}
// and use it here:
public function restored(Post $post)
{
$post->comments()
->onlyTrashed()->where('deleted_at', '>=', $this->deletedAt)
->get()
->each(function ($comment) {
$comment->restore();
});
}
I tried the same using this bit of code in the model and it worked fine for me:
private static $cache = null;
protected static function boot()
{
parent::boot();
static::restoring(function ($model) {
static::$cache = $model->deleted_at;
});
static::restored(function ($model) {
dd(static::$cache);
});
}