Skip to content

Commit 7c4eafa

Browse files
authored
fix: resolve Builder::create() crash when chaining after withoutHook() (#239)
2 parents abb59a2 + 3687f31 commit 7c4eafa

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/Phaseolies/Database/Entity/Builder.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ public function __construct(PDO $pdo, string $table, string $modelClass, int $ro
151151
$this->rowPerPage = $rowPerPage;
152152
}
153153

154+
/**
155+
* Create a new model instance and save it to the database
156+
*
157+
* @param array $attributes
158+
* @return Model
159+
*/
160+
public function create(array $attributes): Model
161+
{
162+
$modelClass = $this->modelClass;
163+
$model = new $modelClass();
164+
$model->fill($attributes);
165+
$model->save();
166+
167+
return $model;
168+
}
169+
154170
/**
155171
* Set the relationship info
156172
*

src/Phaseolies/Database/Entity/Query/InteractsWithModelQueryProcessing.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public static function query(?string $connection = null): Builder
3838
/**
3939
* Disable the execution of model hooks for the current instance.
4040
*
41-
* @return self
41+
* @return \Phaseolies\Database\Entity\Builder
4242
*/
43-
public static function withoutHook(): self
43+
public static function withoutHook(): Builder
4444
{
4545
self::$isHookShouldBeCalled = false;
4646

47-
return app(static::class);
47+
return static::query();
4848
}
4949

5050
/**

0 commit comments

Comments
 (0)