lundi 5 décembre 2016

Laravel Tables/Create and Edit in same form?

Hoping someone can help me. I'm used to procedural code, and I'm currently refactoring an older PHP app into Laravel. A page in the old app had a table layout with each td having an input. These inputs were all an array, and with jquery, you could add a new row to the table to create a new record. Here's a jsfiddle: http://ift.tt/2g2lsQT. It looks a bit like this, to give you an idea, but the Fiddle will help a lot.:

<tr>
  <td><input type="text" id="name[]" size="15" name="name[]"></td>
  <td><input type="text" id="heartrate[]" size="1" name="heartrate[]"></td>
  <td><input type="text" id="intensity[]" size="1" name="intensity[]"></td>
  <td><textarea rows="4" cols="50" id="description[]" name="description[]"></textarea></td>
</tr>

When it saves, it runs through the loop updating each of the old records based on its id in the array up to a max specified by a hidden input at the bottom. Then it inserts the new records.

I'd like to do this using Laravel and form model binding, and not have separate views. I really like this add/edit in the same table/view. For the life of me, despite reading docs and google searching, I can't find a solution. I've looked at syncing, but that is only for many-to-many relationships/pivot tables, an attach won't work, and a save won't work. Can anyone help me out? Thanks!! Loving Laravel so far!

EDIT: What if I just ditched form-model binding and did something like this guy: How to validate multiple records insertion in laravel?. Is that 'wrong'? I could loop through all the "old" records and then insert all the new ones, but that feels a lot like not using the framework and procedural code.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2g06gJ9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire