Best Practices for Custom Helpers in Laravel 5

后端 未结 20 2296
暖寄归人
暖寄归人 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:27

    For Custom Helper Libraries in my Laravel project, I have created a folder with name Libraries in my Laravel/App Directory and within Libraries directory, I have created various files for different helper libraries.

    After creating my helper files I simply include all those files in my composer.json file like this

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

    and execute

    composer dump-autoload
    

提交回复
热议问题