dynamically add fields based on an array
i have a file input, that proccess a csv file.
after the process it outputs an array.
i want filament to print for each row in the array a set of fields in the same form.
example for the final form after the process :
[
['John Doe', 30, 'Developer', '1991-01-01'],
['Jane Doe', 25, 'Designer', '1996-02-02'],
['Alice', 35, 'Manager', '1986-03-03'],
['Bob', 40, 'CEO', '1981-04-04'],
['Charlie', 45, 'CTO', '1976-05-05'],
];
now i want each one to have a set of fields that will look like this
<form method="POST" action="/path/to/your/route">
@csrf
@foreach($users as $index => $user)
<div>
<label for="name_{{ $index }}">Name</label>
<input type="text" id="name_{{ $index }}" name="users[{{ $index }}][name]" value="{{ $user[0] }}">
</div>
<div>
<label for="age_{{ $index }}">Age</label>
<input type="number" id="age_{{ $index }}" name="users[{{ $index }}][age]" value="{{ $user[1] }}">
</div>
<div>
<label for="position_{{ $index }}">Position</label>
<input type="text" id="position_{{ $index }}" name="users[{{ $index }}][position]" value="{{ $user[2] }}">
</div>
<div>
<label for="dob_{{ $index }}">Date of Birth</label>
<input type="date" id="dob_{{ $index }}" name="users[{{ $index }}][dob]" value="{{ $user[3] }}">
</div>
@endforeach
<button type="submit">Submit</button>
</form>
ignore the inconsistencies, this was just an example i wrote.
how to i dup the form inputs based on the array?Solution:Jump to solution
if anyone intrested, i solved it.
basically whenever i want to add fields to the form i can just use the function
$this->form->schema()
.
the issue is that it will overwrite the previous one and only add the latest. so my solution for this was to run a loop of forms, store them in an array and just $this->form->schema($array)
...1 Reply
Solution
if anyone intrested, i solved it.
basically whenever i want to add fields to the form i can just use the function
$this->form->schema()
.
the issue is that it will overwrite the previous one and only add the latest. so my solution for this was to run a loop of forms, store them in an array and just $this->form->schema($array)
the array contains a normal schema syntax.