Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Create Helper Function in Laravel
Arman Rahman
Arman Rahman

Posted on • Edited on

     

Create Helper Function in Laravel

Sometimes we need to create a helper function on the Laravel project to use a function on the whole project.

To create a helper function, we need to create a helper file in the following folder -

app\helpers\helpers.php

on that folder write your function like this -

<?phpif (!function_exists('abc')) {    function abc($parameter)    {        // statement         return xyz;    }}
Enter fullscreen modeExit fullscreen mode

after that we need to add this folder in autoloader on -

composer.json

"autoload": {        "psr-4": {            ///        },        "files":[            "app/helpers/helpers.php"        ]    },
Enter fullscreen modeExit fullscreen mode

Once you add a new path to the files array, you need to dump the autoloader-

composer dump-autoload
Enter fullscreen modeExit fullscreen mode

Then you can access this "abc()" function from anywhere in this project.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Hello! I'm Arman Rahman, a passionate Software Engineer specializing in web application development. With expertise in Laravel, PHP, JavaScript, Ajax, C, MySQL, Bootstrap, and CSS, I create robust and
  • Education
    BSc in CSE
  • Work
    Software Engineer | Web Application Developer
  • Joined

More fromArman Rahman

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp