ViewField in repeater with record data in livewire component

I have a repeater where I have overwritten the add action with a modal. I want to use the Simple layout of the repeater and use a custom viewField with the data of the records. Does anyone know how to pass the data into the viewField? I only want to nicely show the information in the repeater, no logic is applied to the field so I dont think I need a custom field class Best case I think would be to pass the record to the viewData() property but I cant figure out how to acces the current record of the repeater
1 Reply
gladjanus43
gladjanus43OP7mo ago
Repeater::make('transportOrders')
->hiddenLabel()
->defaultItems(0)
->reorderable(false)
->addActionLabel('Create new transport order')
->simple(
ViewField::make('customer_reference')
->view('forms.transport-order-display')
->viewData([
'transportOrder' => $record??
])
)
Repeater::make('transportOrders')
->hiddenLabel()
->defaultItems(0)
->reorderable(false)
->addActionLabel('Create new transport order')
->simple(
ViewField::make('customer_reference')
->view('forms.transport-order-display')
->viewData([
'transportOrder' => $record??
])
)
I would like to do something like this If I display this in my view <div> {{ Log::info(data_get($this, 'data.transportOrders')) }} {{ $getStatePath() }} </div> It does show up in the log with the correct data. However when I call data_get($this, $getStatePath) it does not show up. The regular $getState() function also is not getting the data from the array. I am in a custom livewire component btw Found the solution. $getStatePath returns the item which i specified in the viewField. In this case data.transportOrders.486bc20d-818f-4f48-bf05-c33d4e1fd960.transportOrder However to make my viewField, i needed the entire transportOrder array so i needed to remove the .transportOrder from the getStatePath function
@php
$statePath = \Illuminate\Support\Str::beforeLast($getStatePath(), '.transportOrder');
$state = data_get($this, $statePath);
@endphp

<div>
{{ $state }}
</div>
@php
$statePath = \Illuminate\Support\Str::beforeLast($getStatePath(), '.transportOrder');
$state = data_get($this, $statePath);
@endphp

<div>
{{ $state }}
</div>
This way it is retrieving the entire array and I can build the view. Is this the best method to go about this or are there better ways to do it?
Want results from more Discord servers?
Add your server