Best Practices for Custom Helpers in Laravel 5

后端 未结 20 2024
暖寄归人
暖寄归人 2020-11-22 06:40

I would like to create helper functions to avoid repeating code between views in Laravel 5:

view.blade.php

Foo Formated text: {{ fo

20条回答
  •  太阳男子
    2020-11-22 07:30

    First create helpers.php inside App\Http directory. Then add the following code inside the composer.json

    "autoload": {
            "classmap": [
                "database"
            ],
            "files": [
                "app/Http/helpers.php"
            ],
            "psr-4": {
                "App\\": "app/"
            }
        },
    

    Next run the following command

    composer dump-autoload
    

    Now you can define your custom function inside the helpers.php file.

提交回复
热议问题