Skip to content

Commit 08fe11c

Browse files
authored
Merge pull request #1 from Smoggert/Smoggert-add-queueable-model-classname-hook
Allow hooking the queueable collection logic
2 parents e0d8e3d + 93e8c36 commit 08fe11c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Illuminate/Database/Eloquent/Collection.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,33 @@ public function getQueueableClass()
665665
return;
666666
}
667667

668-
$class = get_class($this->first());
668+
$class = $this->getModelClass($this->first());
669669

670670
$this->each(function ($model) use ($class) {
671-
if (get_class($model) !== $class) {
671+
if ($this->getModelClass($model) !== $class) {
672672
throw new LogicException('Queueing collections with multiple model types is not supported.');
673673
}
674674
});
675675

676676
return $class;
677677
}
678678

679+
/**
680+
* Get the identifiers for all of the entities.
681+
*
682+
* @return array<int, mixed>
683+
*/
684+
protected function getModelClass($model)
685+
{
686+
if(method_exists($model,'getClassNameForSerialization')) {
687+
return $model->getClassNameForSerialization();
688+
}
689+
690+
return get_class($model);
691+
}
692+
693+
694+
679695
/**
680696
* Get the identifiers for all of the entities.
681697
*

0 commit comments

Comments
 (0)