Components

Decoration Fragment

-Make -Asynchrinous event


Make

Sometimes you need to return only part of a template in your HTTP response. For this, you can use Blade Fragments. The Fragment decorator allows you to create corresponding blocks.

You can create a Fragment using the static make() method.

make(array $fields = [])
make(array $fields = [])

Method name() sets the name for the fragment.

use MoonShine\Decorations\Fragment; use MoonShine\Fields\Text; //... public function components(): array { return [ Fragment::make([ Text::make('Name', 'first_name') ]) ->name('fragment-name') ]; } //...
use MoonShine\Decorations\Fragment;
use MoonShine\Fields\Text;
 
//...
 
public function components(): array
{
return [
Fragment::make([
Text::make('Name', 'first_name')
])
->name('fragment-name')
];
}
 
//...

Asynchronous event

You can incorporate an area in a Fragment and set an event on this area, by calling which it will be possible to update the fragment

Fragment::make($fields) ->name('fragment-name'),
Fragment::make($fields)
->name('fragment-name'),

And as an example, let's call an event for successful submission of the form

FormBuilder::make()->async(asyncEvents: 'fragment-updated-fragment-name')
FormBuilder::make()->async(asyncEvents: 'fragment-updated-fragment-name')

You can also pass additional parameters with the request via an array

Fragment::make($fields) ->name('fragment-name') ->updateAsync(['resourceItem' => request('resourceItem')]),
Fragment::make($fields)
->name('fragment-name')
->updateAsync(['resourceItem' => request('resourceItem')]),

Passing parameters

The withParams() method allows you to pass field values with the request using element selectors.

Fragment::make($fields) ->withParams([ 'start_date' => '#start_date', 'end_date' => '#end_date' ]) ->name('fragment-name'),
Fragment::make($fields)
->withParams([
'start_date' => '#start_date',
'end_date' => '#end_date'
])
->name('fragment-name'),