Custom form field inside resource
Hi, i want to insert custom field inside a resource and i'm following this: https://filamentphp.com/docs/3.x/forms/fields/custom#custom-field-classes.
All was ok untill the moment to define my inputs a wire:model. I've an array of input and i don't know how to define wire:model. I also don't know with simple example:
How i can define or retrieve property
name
inside a resource?10 Replies
use
the
getStatePath
is what you used in the make()
of your custom fieldok thanks, but how can i retrieve and save it? consider that i have an array and i want to build a custom function to save only that field
I think the saving prossess will be done in the resource or using some hooks
this seems to work. The only problem now is that TeacherHourInput::make('hours')->label('Hours'), hours should be an array because i've an array of select:
this:
wire:model="data.teacherHour.{{ $indexDay }}.{{ $hour }}"
seems don't workthis is similler to what i did here
https://github.com/lara-zeus/matrix-choice/blob/3.x/resources/views/components/matrix-choice.blade.php
see how it working hope it help
also did you cast your field to array in the model?
GitHub
matrix-choice/resources/views/components/matrix-choice.blade.php at...
multiple choice grid form component for filamentPHP - lara-zeus/matrix-choice
Cast is good option. How can i do that?
i think this piece of code is the way! how do you treated
{{ $applyStateBindingModifiers('wire:model') }}="{{ $supStatPath }}"
backend side?when it cast to array you dont have to do anything 🙂
https://laravel.com/docs/master/eloquent-mutators#attribute-casting
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
ah ok. thanks but this is not my case. I have created a custom
Field
in Filament with the view part as i posted above. My problem now is that i have a custom Field that is called teacherHour but the view contains an array of select that should be binded with that field in the resource:
and i don't know how to make teacherHour an arrayis teacherHour a column in your database?
or a relationship? how you want to store them in the database?
no there isn't or better: i've a
Teacher
model and i've a relationship with a TeacherTimetable
model
But i want to handle in my custom way the update of that in the EditTeacher action with:
Now i'm getting myself in a simple scenario. the problem now is that i'm using this in the resource form
But i can't initialize or interact with the field in forms.components.teacher-hour-input
no way to set that input field to "testtttest" default value