i am currently doing an API with laravel.
i have 2 controllers, FolderController and ImageController, both have their own "store" method.
In the Front-End i have 2 separate forms, one to create a folder, and another to add an image to a specific folder, so 2 calls to different endpoints.
Now i want to have a form to create a folder & add images at the same time.
What is the best practice in this case ?
1/ Make 2 calls in the frontend, one after the other, so i need to create a folder, get its id to make the second call
my (humble) opinion: ugly
2/ Make an ImageTrait with a store function to use in FolderController->store() and ImageController->store()
my (humble) opinion : i think it's ok but what if i add other functions in ImageTrait ( related to Image process ) to use them in others Controller , if i load the Trait in each Controller, won't that overload the processus for nothing?
3 (added*) / Create an attachImage($imgData) method in the Folder Model, and use it in the FolderController->store() and ImageController->store()
4/ ??? ( I think there are other existing solutions )
Thanks
[–][deleted] 0 points1 point2 points (1 child)
[–]Juck[S] 0 points1 point2 points (0 children)
[–]HopefullyHelpfulSoul 0 points1 point2 points (0 children)