Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set global methods by laravel

Shulou Source: shulou.com Published: 2022-06-03 10:51:18 11月15日 Update

Editor to share with you how to set the overall method of laravel, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Setting method: 1, app directory to build a Common folder, in which a new "function.php" file, used to store public functions; 2, configuration "composer.json" file; 3, in the project directory, the implementation of the "composer dump-autoload" statement.

The operating environment of this tutorial: windows7 system, Laravel5 version, Dell G3 computer.

Laravel sets the global method

1. Create a Common folder under app. Create a function.php under Common and put it into a public function.

Function test () {echo 'this is a test';}

2. Under the project directory, configure composer.json and add the following code

"autoload": {"files": ["app/Common/function.php"]}

3. Execute the following command under the project directory

Composer dump-autoload above is all the content of the article "how to set the global method for laravel". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Methods files directories global articles projects contents functions folders configurations not much code commands most tutorials more environment computer knowledge systems Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB MySQL Apple macOS