Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed May 28, 2024
1 parent ac99dfd commit 19d733e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
28 changes: 28 additions & 0 deletions resources/views/fields/date.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="form-group--row" x-data>
<label class="form-label" for="{{ $attrs->get('id') }}">
{{ $label }}
@if($attrs->get('required'))
<span class="required-marker">*</span>
@endif
</label>
<div class="form-group--stacked">
@if($prefix)
<div class="form-group-label" style="white-space: nowrap;">{!! $prefix !!}</div>
@endif
<input {{ $attrs }} value="{{ $value }}" x-ref="input">
@if($suffix)
<div class="form-group-label" style="white-space: nowrap;">{!! $suffix !!}</div>
@endif
</div>
<span class="form-description">
<button type="button" class="btn btn--light btn--sm" x-on:click="$refs.input.value = ''">
{{ __('Clear') }}
</button>
</span>
@if($invalid)
<span class="field-feedback field-feedback--invalid">{!! $error !!}</span>
@endif
@if($help)
<span class="form-description">{!! $help !!}</span>
@endif
</div>
5 changes: 5 additions & 0 deletions src/Fields/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

class Date extends Field
{
/**
* The Blade template.
*/
protected string $template = 'root::fields.date';

/**
* The date format.
*/
Expand Down
8 changes: 6 additions & 2 deletions src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ public function asSubResource(bool $value = true): static
{
$this->asSubResource = $value;

$this->format(function (Request $request, Model $model): ?int {
return $model->getAttribute(sprintf('%s_count', $this->getRelationName()));
});

return $this;
}

Expand Down Expand Up @@ -615,15 +619,15 @@ public function handleFormRequest(Request $request, Model $model): void

$model->save();

$this->saved($request, $model);

if (in_array(HasRootEvents::class, class_uses_recursive($model))) {
$model->recordRootEvent(
$model->wasRecentlyCreated ? 'Created' : 'Updated',
$request->user()
);
}

$this->saved($request, $model);

DB::commit();
} catch (Throwable $exception) {
report($exception);
Expand Down
7 changes: 3 additions & 4 deletions src/Resources/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ public function mapModel(Request $request, Model $model): array
'model' => $model,
'abilities' => $this->mapModelAbilities($request, $model),
'fields' => $this->resolveFields($request)
->subResource(false)
->authorized($request, $model)
->visible('index')
->mapToDisplay($request, $model),
Expand All @@ -448,15 +447,15 @@ public function handleFormRequest(Request $request, Model $model): void

$model->save();

$this->saved($request, $model);

if (in_array(HasRootEvents::class, class_uses_recursive($model))) {
$model->recordRootEvent(
$model->wasRecentlyCreated ? 'Created' : 'Updated',
$request->user()
);
}

$this->saved($request, $model);

DB::commit();
} catch (Throwable $exception) {
report($exception);
Expand Down Expand Up @@ -575,7 +574,7 @@ public function toIndex(Request $request): array
'filters' => $this->resolveFilters($request)
->authorized($request)
->renderable()
->map(function (RenderableFilter $filter) use ($request, $model): array {
->map(static function (RenderableFilter $filter) use ($request, $model): array {
return $filter->toField()->toInput($request, $model);
})
->all(),
Expand Down

0 comments on commit 19d733e

Please sign in to comment.