Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Sep 25, 2023
1 parent 6b22cba commit 3670477
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 82 deletions.
8 changes: 8 additions & 0 deletions src/Form/Fields/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ public function morphToMany(string $label, string $modelAttribute = null, Closur
return $this->field(MorphToMany::class, $label, $modelAttribute, $relation);
}

/**
* Make a new meta field.
*/
public function meta(string $label, string $modelAttribute = null, Closure|string $relation = null): Meta
{
return $this->field(Meta::class, $label, $modelAttribute, $relation);
}

/**
* Persist the request value on the model.
*/
Expand Down
12 changes: 5 additions & 7 deletions src/Form/Fields/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ public function __construct(Form $form, string $label, string $modelAttribute =
->one()
->ofMany(
[$related->getCreatedAtColumn() => 'MAX'],
function (Builder $query) use ($related): Builder {
return $query->where($related->qualifyColumn('key'), $this->getModelAttribute());
},
fn (Builder $query): Builder => $query->where($related->qualifyColumn('key'), $this->getModelAttribute()),
'metaData'
)
->withDefault(['key' => $this->getModelAttribute()]);
};

$this->asText();

parent::__construct($form, $label, $modelAttribute, $relation);

$this->asText();
}

/**
Expand All @@ -57,7 +55,7 @@ public function getRelationName(): string
*/
public function as(string $field, Closure $callback = null): static
{
$this->field = new $field($this->label, $this->getModelAttribute());
$this->field = new $field($this->form, $this->label, $this->getModelAttribute());

if (! is_null($callback)) {
call_user_func_array($callback, [$this->field]);
Expand Down Expand Up @@ -227,7 +225,7 @@ public function getValue(): mixed
public function resolveValue(Request $request): mixed
{
if (is_null($this->valueResolver)) {
$this->valueResolver = static function (Model $model, mixed $value): mixed {
$this->valueResolver = static function (Request $request, Model $model, mixed $value): mixed {
return $value?->value;
};
}
Expand Down
74 changes: 0 additions & 74 deletions src/Form/Panel.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function store(Request $request, Resource $resource): RedirectResponse

$model = $resource->getModelInstance();

$resource->form($model)->handle($request);
$resource->toForm($request, $model)->handle($request);

return Redirect::to($resource->modelUrl($model))
->with('alerts.resource-created', Alert::success(__('The resource has been created!')));
Expand Down

0 comments on commit 3670477

Please sign in to comment.