Home > Article > PHP Framework > Laravel uses composer to load custom functions and custom classes (picture and text)
The content of this article is about the method (pictures and text) of laravel using composer to load custom functions and custom classes. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. helped.
During development, some custom functions and custom classes will be encapsulated. This article will talk about how to use composer to implement automatic loading.
Custom function
There are three steps to implement automatic loading.
1. Create a file. Create a Helpers.php file in the app directory for custom functions;
2. Modify the composer.json file and add the following statements
Finally, execute composer dump-autoload in the project directory
Then you can use the custom function in the code. It should be noted that the custom function needs to check whether has been defined. For details, please refer to the code in GitHub.
Custom class
Custom class is the same as above, also three steps, with some minor changes. 1. The same method is used to create files, but the difference is that the Libraries directory is created under the app for easy management. You can create custom classes in Libraries. Be sure to add the namespace app\Libraries; 2. Also modify the composer.json file as followsExecute composer dump-autoload.
The above is the detailed content of Laravel uses composer to load custom functions and custom classes (picture and text). For more information, please follow other related articles on the PHP Chinese website!