Skip to content

Commit

Permalink
fix(eloquent)!: new ModelHelper(Model::class) will be identical to …
Browse files Browse the repository at this point in the history
…`new ModelHelper(Model::query())` (makes no sense to create a query with invalid constraints for relations).
  • Loading branch information
LastDragon-ru committed Sep 15, 2023
1 parent 294bb1f commit 1e4e213
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/eloquent/src/ModelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ class ModelHelper {
* @param Builder<TModel>|TModel|class-string<TModel> $model
*/
public function __construct(Builder|Model|string $model) {
if (is_string($model)) {
$model = new $model();
if ($model instanceof Builder) {
$this->builder = true;
$this->model = $model->getModel();
} elseif (is_string($model)) {
$this->builder = true;
$this->model = new $model();
} else {
$this->builder = false;
$this->model = $model;
}

$this->builder = $model instanceof Builder;
$this->model = $model instanceof Builder
? $model->getModel()
: $model;
}

protected function isBuilder(): bool {
Expand Down

0 comments on commit 1e4e213

Please sign in to comment.