A
A
Anton2016-06-06 01:18:14
Laravel
Anton, 2016-06-06 01:18:14

How and where to create your own function and how to access it?

Hello!
Can you please tell me if it is possible to create your own separate functions (without using a controller. For example, laravel-function dd() ) in Laravel? If so, how and where should they be created and how should they be accessed after that? An example of what I want to do: I want to create a function that will show whether the user is online or not. And call it where the output of users or a specific user occurs. If there is a better solution to this problem, please advise.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2016-06-06
@Yadalay

The solution to my question was this way:
jonybang.ru/laravel-5-2-custom-helpers

A
Andrzej Wielski, 2016-06-06
@wielski

Create helpers.php file in app folder
In composer.json file add lines to autoload

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

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

You can create any functions in this file.
Also don't forget to run composer dump-autoload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question