I am sending JSON to an API that I am building. For this particular instance, I am create a "contacts" database.
The client side has the ability to create contacts and related contacts that can be sent to the api. Eg. Individual or a married Couple or an Organisation with a specific Individual contact.
My API is currently set to handle one set of input, eg name, address etc.
But I need handle the option of multiple contacts in one payload.
I have a controller, an object the handles the form data, and the model that does the specific CRUD for my app.
I am deliberating over whose job it is to process the data - especially if there is multiple records to process.
One one hand, the form object can check the integrity of the request and the make several calls to the model->create method.
eg. sudo
For Each Record
validate
Success: Pass record to model
Model->create
OR
Should I pass the entire recordset to the model.
eg. sudo
Form Class: Check Integrity
Model->Create( All Records )
Model: loop and create.
Or somewhere between the two maybe? I keep second-guessing myself.
My controller (http://laravel.io/bin/y6Dma)
Form Processing Object (http://laravel.io/bin/3B9rP)
Model (http://laravel.io/bin/Md4K0)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community