1

I'm new in Laravel framework and i need an option to add and remove a row from a form. Is there maybe some easier and faster way in Laravel or i need to make it "oldschool" like in this video https://www.youtube.com/watch?v=iaeCSh7YJDM

enter image description here

lewis4u
  • 14,256
  • 18
  • 107
  • 148

2 Answers2

4

Adding and removing form elements dynamically is pure frontend feature, so yes, you should do this 'oldschool' way with JavaScript.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

Well @lewis4u, it depends whether you want to give the user a seemless experience or deal with saving, updating, adding and deleting rows on the php side and let the user wait for the php to answer.

I guess you have a view which generates what the user sees. Then you can either do it with JavaScript, which is actually not so 'oldschool' or do it with php.

Frontend Solution There are several ways handling that on the Frontend. Using plain JS or Frontend Frameworks like AngularJS, VueJS, Ember, jQuery, ... you name it. That will all come down in the end of dynamically adding / removing / showing / hiding elements. This will be MUCH faster, you can add neat animations like slideUp and it's much less code than doing something on the backend. If you don't use a framework write a template and add/remove it. If you use AngularJS do a ng-repeat based on a certain model.

The easy- and fastest way do achieve this is with jQuery or plain JS and using a template.

Backend Solution (Partial) I won't go deeper into this. Doing this with PHP as I just wrote can get messy but it's possible. When the users clicks a corresponding button just insert, update, delete the information on the database and refresh the page and make sure - depending on your functionality - to set a 'isSubmitted'-flag is set once the submit button is clicked (to filter out )

hogan
  • 1,434
  • 1
  • 15
  • 32