srd9's avatar
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

0 likes
3 replies
christian-qode's avatar

@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.

srd9's avatar
Level 3

Thank you guys for your help,

@sinnbeck I ended up searching and reading more about actions, thanks for the hint

Please or to participate in this conversation.