ViewField Form error.

I have a form with a ViewField in it.
ViewField::make('users')
->columnSpan('full')
->label(label: 'Company Users')
->view('livewire.components.companies.company-users'),
ViewField::make('users')
->columnSpan('full')
->label(label: 'Company Users')
->view('livewire.components.companies.company-users'),
When saving, I get an error stating that users does not exist. Aside from the fact it does (in my Company model), I am unsure as to why - as a ViewField, that Filament is attempting to save the users. Am I getting something wrong with the the nomenclature?
Solution:
Oh goodness me. My sincere apologies @Leandro Ferreira. I've changed the ViewField to be just a View and it's all working now. ...
Jump to solution
3 Replies
LeandroFerreira
What about the code of the view?
pinpointzero
pinpointzero4w ago
Hi Leandro, Thanks so much for responding.
<div>
@if ($getRecord() && $getRecord()->users)
<div class="filament-tables-component">
@if ($getRecord()->users->count() > 0)
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700 filament-table">
<thead class="bg-gray-50 dark:bg-gray-700">
...
</thead>
<tfoot></tfoot>
<tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
@foreach($getRecord()->users as $user)
<tr class="table-striped">
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 dark:text-gray-200">
{{ $user->id }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-300">
{{ $user->name }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-300">
{{ $user->email }}
</td>
</tr>
@endforeach
</tbody>
</table>
@else
<div class="text-center">
There are no Users bound to {{ $getRecord()->name }} presently.
</div>
@endif
@endif
</div>
</div>
<div>
@if ($getRecord() && $getRecord()->users)
<div class="filament-tables-component">
@if ($getRecord()->users->count() > 0)
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700 filament-table">
<thead class="bg-gray-50 dark:bg-gray-700">
...
</thead>
<tfoot></tfoot>
<tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
@foreach($getRecord()->users as $user)
<tr class="table-striped">
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 dark:text-gray-200">
{{ $user->id }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-300">
{{ $user->name }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-300">
{{ $user->email }}
</td>
</tr>
@endforeach
</tbody>
</table>
@else
<div class="text-center">
There are no Users bound to {{ $getRecord()->name }} presently.
</div>
@endif
@endif
</div>
</div>
That's the view code as it stands, and, there are references. I've always assumed that a ViewField isn't accounted for when saving data in a form.
Solution
pinpointzero
pinpointzero4w ago
Oh goodness me. My sincere apologies @Leandro Ferreira. I've changed the ViewField to be just a View and it's all working now. Apologies.
Want results from more Discord servers?
Add your server