I'm using Laravel the first time and am working on an application with which I can generate invoices. Each invoice can have multiple positions. This means there is a one to many relation.
When creating a new invoice there are the inputs for the first position and via ajax the inputs to add more positions can be added. I use an array for the positions and make a random index.
<?php $c = rand(); ?>
{!! Form::text('position['.$c.'][title]', null, ['class' => 'form-control']) !!}
{!! Form::textarea('position['.$c.'][description]', null, ['class' => 'form-control']) !!}
This works perfectly fine so far.
Now when it comes to editing an invoice the problem arises. What do I have to do to get the Form-Model Binding working?
Now I check how many positions I have and load the snippet with the position inputs that often and pass in the data.
@foreach( $document->positions as $position)
@include('documents._position', [$position])
@endforeach
But the values don't appear in the input fields. What do I have to do to get this working?
And a second thing would be how can I sync the positions? I now just delete the existing ones after editing an invoice and make new ones. Is there a better way to do this?
Aucun commentaire:
Enregistrer un commentaire