How and where to create your function and how to handle it?

Hello!
Tell me, please, is it possible to create your individual functions (not using the controller. For example, laravel-function dd() ) in Laravel? If so, how and where you want to create and then refer to them? An example of what I want to do: I want to create a function that will show online if user is present or not. And call it where is the output of users or a specific user. If you have solve this task better, then please advise.
July 8th 19 at 16:35
2 answers
July 8th 19 at 16:37
Solution
Solution of my question here was this:
jonybang.ru/laravel-5-2-custom-helpers
Well, it's not quite "a function" is a class-helper. Expected, not knowing how to ask a question correctly - you will not get a desired response. - edmond.Strom commented on July 8th 19 at 16:40
: the question I asked and You understood it. Just, unfortunately, found the option better than yours. In this case does not have to touch composer, and you can access the class anywhere. - Arthur_McCullough70 commented on July 8th 19 at 16:43
July 8th 19 at 16:39
Create a file helpers.php in the app directory
In the file composer.json add lines in autoload

"files": [
"app/helpers.php"
 ]


To get something like this:
"autoload": {
 "classmap": [
"database"
],
 "psr-4": {
 "App\\": "app/"
},
 "files": [
"app/helpers.php"
]
 },


In this file, you can create any function.
Don't forget to run composer dump-autoload
1. Create:
Just function name() {
// Function description.
}
So?
-------
2. And how to use it then? - edmond.Strom commented on July 8th 19 at 16:42
: In normal php in the case of controllers / models, or ordinary sintaksa inside Blade templates {{ name() }} - Arthur_McCullough70 commented on July 8th 19 at 16:45
: what should be the structure of the file helpers?
// And then just functions? Or what? - Arthur_McCullough70 commented on July 8th 19 at 16:48
Yes. You even know php? :) - edmond.Strom commented on July 8th 19 at 16:51
: of course. With this feature in Laravel, I have never encountered. You never know, ATM its rules.
Tell me more please how I contact the models? I want to make a function that shows whether the user is currently. - Arthur_McCullough70 commented on July 8th 19 at 16:54
: found here and so way more - jonybang.ru/laravel-5-2-custom-helpers - edmond.Strom commented on July 8th 19 at 16:57
: As usual. \App\User for example - Arthur_McCullough70 commented on July 8th 19 at 17:00

Find more questions by tags Laravel