diff --git a/src/Phaseolies/Database/Entity/Builder.php b/src/Phaseolies/Database/Entity/Builder.php index 63be900..ce6773b 100644 --- a/src/Phaseolies/Database/Entity/Builder.php +++ b/src/Phaseolies/Database/Entity/Builder.php @@ -151,6 +151,22 @@ public function __construct(PDO $pdo, string $table, string $modelClass, int $ro $this->rowPerPage = $rowPerPage; } + /** + * Create a new model instance and save it to the database + * + * @param array $attributes + * @return Model + */ + public function create(array $attributes): Model + { + $modelClass = $this->modelClass; + $model = new $modelClass(); + $model->fill($attributes); + $model->save(); + + return $model; + } + /** * Set the relationship info * diff --git a/src/Phaseolies/Database/Entity/Query/InteractsWithModelQueryProcessing.php b/src/Phaseolies/Database/Entity/Query/InteractsWithModelQueryProcessing.php index ce2410c..5c30434 100644 --- a/src/Phaseolies/Database/Entity/Query/InteractsWithModelQueryProcessing.php +++ b/src/Phaseolies/Database/Entity/Query/InteractsWithModelQueryProcessing.php @@ -38,13 +38,13 @@ public static function query(?string $connection = null): Builder /** * Disable the execution of model hooks for the current instance. * - * @return self + * @return \Phaseolies\Database\Entity\Builder */ - public static function withoutHook(): self + public static function withoutHook(): Builder { self::$isHookShouldBeCalled = false; - return app(static::class); + return static::query(); } /**