How to set up ajax crud in laravel 5.4 with dynamic input fields


My goal is to make a post CRUD that has a variable ammount of inputfields. with a normal CRUD setup i run in to the problem that the variable fields vanish when the user refreshes the page or when the post doesn't get trough te validation. To fix this i was thinking about using ajax to make it possible to save the added inputfields directly into the database. How would i go about this?

The inputfields belong to the post so the post should exist when saving the inputfields. Should i start with an empty saved post to accomplish this or is this bad practice?

Posts in the db:

post  - id  - title  

inputfields in the db:

inputfield  - id  - post_id  - title  - body  

how i see it:

  • user creates a new post (this stores an empty post in the db).
  • the inputfields are added and stored in the db using ajax with it's own CRUD on the create page
  • user fills in any forms and input fields also with ajax so it can be updated inbetween .
  • when the post is stored any empty inputfields are destroyed.

I hope someone can help as i have no real jquery and ajax experience.