Skip to content

Commit

Permalink
docs: Field in the Closure
Browse files Browse the repository at this point in the history
  • Loading branch information
DissNik committed Nov 12, 2023
1 parent 1a54f06 commit 2dae961
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion resources/views/pages/ru/fields/file.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function fields(): array
{
return [
File::make('File', 'file')
->customName(fn(UploadedFile $file) => Str::random(10) . '.' . $file->extension()) // [tl! focus]
->customName(fn(UploadedFile $file, Field $field) => Str::random(10) . '.' . $file->extension()) // [tl! focus]
];
}

Expand Down
26 changes: 13 additions & 13 deletions resources/views/pages/ru/fields/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public function fields(): array
return [
Slug::make('Slug')
->setLabel(
fn() => $this->getItem()?->exists
fn($label, Field $field) => $field->getData()?->exists
? 'Slug (do not change)'
: 'Slug'
: 'Slug')
) // [tl! focus:-4]
];
}
Expand Down Expand Up @@ -329,7 +329,7 @@ public function fields(): array
{
return [
Text::make('Title')
->badge('green') // [tl! focus]
->badge(fn($status, Field $field) => 'green') // [tl! focus]
];
}

Expand Down Expand Up @@ -511,7 +511,7 @@ public function fields(): array
{
return [
Text::make('Thumbnail')
->changePreview(function ($value) {
->changePreview(function ($value, Field $field) {
return view('moonshine::ui.image', [
'value' => Storage::url($value)
]);
Expand Down Expand Up @@ -569,7 +569,7 @@ public function fields(): array
{
return [
Text::make('Slug')
->when($this->getItem()?->exist, fn(Field $field) => $field->locked()) // [tl! focus]
->when(fn($field) => $field->getData()?->exists, fn(Field $field) => $field->locked()) // [tl! focus]
];
}

Expand Down Expand Up @@ -597,9 +597,9 @@ public function fields(): array
return [
Text::make('Slug')
->when(
$this->getItem()?->exist,
fn(Text $field) => $field->locked(),
fn(Text $field) => $field->hidden()
fn($field) => $field->getData()?->exists,
fn(Field $field) => $field->locked(),
fn(Field $field) => $field->hidden()
) // [tl! focus:-4]
];
}
Expand All @@ -625,8 +625,8 @@ public function fields(): array
Text::make('Slug')
->unless(
auth('moonshine')->user()->moonshine_user_role_id === 1,
fn(Text $field) => $field->readonly()->hideOnCreate(),
fn(Text $field) => $field->locked()
fn(Field $field) => $field->readonly()->hideOnCreate(),
fn(Field $field) => $field->locked()
) // [tl! focus:-4]
];
}
Expand Down Expand Up @@ -758,7 +758,7 @@ public function fields(): array
{
return [
Text::make('Title')
->onBeforeApply(function(Model $item, $value) {
->onBeforeApply(function(Model $item, $value, Field $field) {
//
return $item;
}) // [tl! focus:-3]
Expand All @@ -777,7 +777,7 @@ public function fields(): array
{
return [
Text::make('Title')
->onAfterApply(function(Model $item, $value) {
->onAfterApply(function(Model $item, $value, Field $field) {
//
return $item;
}) // [tl! focus:-3]
Expand All @@ -796,7 +796,7 @@ public function fields(): array
{
return [
Text::make('Title')
->onAfterDestroy(function(Model $item, $value) {
->onAfterDestroy(function(Model $item, $value, Field $field) {
//
return $item;
}) // [tl! focus:-3]
Expand Down
4 changes: 2 additions & 2 deletions resources/views/pages/ru/fields/preview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function fields(): array
{
return [
Preview::make('Status')
->badge(fn($status) => $status === 1 ? 'green' : 'gray') // [tl! focus]
->badge(fn($status, Field $field) => $status === 1 ? 'green' : 'gray') // [tl! focus]
];
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public function fields(): array
Preview::make('Link')
->link('https://moonshine-laravel.com', blank: false), // [tl! focus]
Preview::make('Link')
->link(fn($link) => $link, fn() => 'Go') // [tl! focus]
->link(fn($link, Field $field) => $link, fn($name, Field $field) => 'Go') // [tl! focus]
];
}

Expand Down
6 changes: 3 additions & 3 deletions resources/views/pages/ru/fields/shared/async_search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public function fields(): array
->asyncSearch(
'title',
10,
asyncSearchQuery: function (Builder $query) {
asyncSearchQuery: function (Builder $query, Field $field) {
return $query->where('id', '!=', 2);
},
asyncSearchValueCallback: function ($country) {
asyncSearchValueCallback: function ($country, Field $field) {
return $country->id . ' | ' . $country->title;
},
'{{ route('async') }}'
Expand Down Expand Up @@ -94,7 +94,7 @@ public function fields(): array
Select::make('Country', 'country_id'), // [tl! focus]
{{ $field }}::make({!! $field === 'BelongsToMany' ? 'Cities' : 'City' !!}, resource: new CityResource())->asyncSearch(
'title',
asyncSearchQuery: function (Builder $query, Request $request): Builder {
asyncSearchQuery: function (Builder $query, Request $request, Field $field): Builder {
return $query->where('country_id', $request->get('country_id'));
} // [tl! focus:-2]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function fields(): array
{
return [
{{ $field }}::make({!! $field === 'BelongsToMany' ? 'Categories' : 'Category' !!}, resource: new CategoryResource())
->valuesQuery(fn(Builder $query) => $query->where('active', true)) // [tl! focus]
->valuesQuery(fn(Builder $query, Field $field) => $query->where('active', true)) // [tl! focus]
];
}

Expand Down

0 comments on commit 2dae961

Please sign in to comment.