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

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

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.

0

Thanks for the reply.

How do you register as a global function?

thanks

0

Take a look: http://stackoverflow.com/questions/4458837/how-to-define-global-functions-in-php

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

0

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

https://laracasts.com/lessons/laravel-5-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)

https://laracasts.com/lessons/laravel-5-events

Have fun!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ottz0 ottz0 Joined 15 Nov 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.