Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

erhsaikhasif's avatar

how to create helpers file in lumen

Hello, I want to define functions somewhere in lumen and this function as common function in controllers. As for example to define function rand_String() function somewhere and use this function in controller file. Please help me, I am new in lumen.

0 likes
3 replies
davielee's avatar
davielee
Best Answer
Level 11

This isn't necessarily a Lumen specific thing, but more of a Composer thing.

In your composer.json file, you can add this line under autoload (The rest of the file has been truncated for brevity).

{
    "autoload": {
        "files": [
            "path/to/helpers.php"
        ]
    }
}

Then just run composer dump-autoload and you should be good to go.

4 likes

Please or to participate in this conversation.