Skip to content

Commit e7daa12

Browse files
committed
Allow model overrule
1 parent 5693f4b commit e7daa12

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

src/Forms/Concerns/WithSession.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function restore(): void
2424

2525
public function store(): void
2626
{
27-
if (! $this->storeWhen()) {
27+
if (! $this->useStore() || ! $this->storeWhen()) {
2828
return;
2929
}
3030

src/Models/Forms/CreateForm.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66

77
abstract class CreateForm extends Form
88
{
9-
protected ?string $model = null;
9+
protected static ?string $model = null;
1010

1111
public function submit(): void
1212
{
13-
$this->canCreate($this->model);
13+
$this->canCreate(static::modelClass());
1414

1515
parent::submit();
1616
}
1717

18-
protected function set(string $class): void
18+
protected function handle(): void
1919
{
20-
$this->canCreate($class);
21-
22-
$this->model = $class;
20+
app(static::modelClass())::create(
21+
$this->all()
22+
);
2323
}
2424

25-
protected function handle(): void
25+
protected static function modelClass(): ?string
2626
{
27-
app(static::$model)::create($this->all());
27+
return static::$model;
2828
}
2929
}

src/Models/Forms/UpdateForm.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,12 @@ public function delete(): void
2222
{
2323
$this->canDelete($this->model);
2424

25-
$this->model->delete();
26-
}
27-
28-
protected function set(Model $model): void
29-
{
30-
$this->canUpdate($model);
31-
32-
$this->model = $model;
25+
$this->model->deleteOrFail();
3326
}
3427

3528
protected function handle(): void
3629
{
37-
$this->model->update(
30+
$this->model->updateOrFail(
3831
$this->all()
3932
);
4033
}

0 commit comments

Comments
 (0)