diff --git a/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php b/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php index cc759bba42c1..0d0b79c39057 100644 --- a/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php +++ b/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php @@ -42,7 +42,7 @@ protected function getRestoredPropertyValue($value) return is_array($value->id) ? $this->restoreCollection($value) - : (new $value->class)->newQuery()->useWritePdo()->findOrFail($value->id); + : $this->getQueryForModelRestoration(new $value->class)->useWritePdo()->findOrFail($value->id); } /** @@ -59,7 +59,28 @@ protected function restoreCollection($value) $model = new $value->class; - return $model->newQuery()->useWritePdo() + return $this->getQueryForModelRestoration($model)->useWritePdo() ->whereIn($model->getQualifiedKeyName(), $value->id)->get(); } + + /** + * Get the query for restoration. + * + * @param \Illuminate\Database\Eloquent\Model $model + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function getQueryForModelRestoration($model) + { + return $this->restoresModelsWithoutScopes() ? $model->newQueryWithoutScopes() : $model->newQuery(); + } + + /** + * Determines whether to restore model identifiers w/o scope. + * + * @return bool + */ + protected function restoresModelsWithoutScopes() + { + return true; + } }