Home > PHP Framework > Laravel > Laravel uses composer to load custom functions and custom classes (picture and text)

Laravel uses composer to load custom functions and custom classes (picture and text)

不言
Release: 2019-01-08 11:08:42
forward
3023 people have browsed it

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

Laravel uses composer to load custom functions and custom classes (picture and text)

Finally, execute composer dump-autoload in the project directory

Laravel uses composer to load custom functions and custom classes (picture and text)

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 follows

Laravel uses composer to load custom functions and custom classes (picture and text)

Execute 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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template