Helpers:
We add arrayhelper.php to App\Helpers folder Then we add
"files": [
"app/helpers/arrayhelper.php",
]
to section
"autoload": {
}
in composer.json.
Now it's possible to define methods and use them globally.
Static methods:
make class ArrayHelper define static method (e.g. doSmthg()
) and then it's possible to call it like this ArrayHelper.doSmthg()
Question:
if there is some benefits (e.g. better performance, less memory usage) of using helpers in Laravel or it's just matter of habit? How about overlapping of methods, e.g. I have to add() methods in different helper files. If I use static methods, it's solves the problem:
CustomClass::add()
and
CustomAnotherClass::add()
How to choose between helpers and static methods?
P.S. There was some similar questions, but I read through all answers and I didn't find what I exactly wanted to know.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire