Hi everyone,
I'd like to get some hints from you how can I manage such situation.
Let's say I have a form from which the user can upload an image.
For such task, we could retrieve the image's information with:
public function store(Request $request)
{
$variable = $request->file('product-imagem');
// Method goes on
}
But in my situation, I have a number of actions to perform with that file. This is an hipotetical example, no real situation here.
An example of code could be:
public function store(Request $request)
{
$image = $request->file('product-imagem');
$resize = $image->resize(x, y);
if (!$resize->isValid()) {
throw new ResizeInvalidException(...);
}
$image->sendImageToAnExternalService();
$image->doThis();
$image->doThat();
// After several things with just the image uploaded, I'll finally save the form
Example::create($request->all());
return redirect("/some-location");
}
You see, there's way too much logic in that controller. One option I see is: create a method on the controller to place all that image logic (previous to Example::create()), but then it looks like I'm just moving the "dirt" around. And it doesn't seem to be a case for a service. Where could I place all this code?
This whole "image handling" is just an example. The wider question would be: if I have to treat data from a form, for example, before I save it, where is it likely to be all this code?
I hope my question is clear. Any help is appreciated.