Support the ongoing development of →
Configuration Eloquent
Last updated 2 years ago.

Please don't use a facade for this. Instead you should see if you can create a trait. Since you are going to be reusing the functions within a class, this makes an easy way to share similar things around the codebase.

If they don't really fit into a trait then you can make a helper class to inject around (although this can be considered a code smell) or you can just register the functions as global functions and call them from anywhere you want without issue.

Last updated 9 years ago.

Traits are meant to be additional functionality on a model, not a reusable function.

What is the difference between registering global function and a fasade? Globals will pollute global namespace, which is not a great idea.


Thanks for the reply.

How do you register as a global function?



Take a look:

The second answer (the one with 9 upvotes) is interesting.


In my opinion, for reusable code you should try separating your logic into commands.

Asuming you have a "HelloCommand" you can call it from any controller/ artisan command using the DispachesCommand Trait

$this->dispatch(new HelloCommand($argument1, $argument2...));

You can throw events from a command (if you need some more stuff later)

Have fun!


Sign in to participate in this thread!


Your banner here too?

ottz0 ottz0 Joined 15 Nov 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.