@sina93 You should create a trait, this is not a specific Laravel but generic PHP solution. I often create an App\Trait directory in my project.
Nov 1, 2022
3
Level 3
Best way to define a single piece of code (function) to use in some of controllers
Hi everyone, Sorry for asking this,
I want to have a function to use in some of my controllers (for example for finishing the pending image uploads and creating thumbnails), I don't know really where to define it.
Should I define it as a custom helper function? Or in a custom class (which I don't know where is the best place to store it and call it properly in Laravel structure)
I want to know the best way
Thanks in advance
Level 102
Personally I like to use actions. Makes it easy to test, and you can just inject the class where you need it
Please or to participate in this conversation.