Skip to content

Commit

Permalink
Allow model overrule
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Apr 16, 2024
1 parent 5693f4b commit e7daa12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Forms/Concerns/WithSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function restore(): void

public function store(): void
{
if (! $this->storeWhen()) {
if (! $this->useStore() || ! $this->storeWhen()) {
return;
}

Expand Down
16 changes: 8 additions & 8 deletions src/Models/Forms/CreateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

abstract class CreateForm extends Form
{
protected ?string $model = null;
protected static ?string $model = null;

public function submit(): void
{
$this->canCreate($this->model);
$this->canCreate(static::modelClass());

parent::submit();
}

protected function set(string $class): void
protected function handle(): void
{
$this->canCreate($class);

$this->model = $class;
app(static::modelClass())::create(
$this->all()
);
}

protected function handle(): void
protected static function modelClass(): ?string
{
app(static::$model)::create($this->all());
return static::$model;
}
}
11 changes: 2 additions & 9 deletions src/Models/Forms/UpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@ public function delete(): void
{
$this->canDelete($this->model);

$this->model->delete();
}

protected function set(Model $model): void
{
$this->canUpdate($model);

$this->model = $model;
$this->model->deleteOrFail();
}

protected function handle(): void
{
$this->model->update(
$this->model->updateOrFail(
$this->all()
);
}
Expand Down

0 comments on commit e7daa12

Please sign in to comment.