Home > PHP Framework > Laravel > How to set global method in laravel

How to set global method in laravel

青灯夜游
Release: 2023-01-13 00:40:29
Original
2806 people have browsed it

Setting method: 1. Create a Common folder in the app directory, and create a new "function.php" file in it to store public functions; 2. Configure the "composer.json" file; 3. In the project directory, execute the "composer dump-autoload" statement.

How to set global method in laravel

The operating environment of this tutorial: Windows 7 system, Laravel version 5, Dell G3 computer.

laravel settings global method

1. Create a Common folder under the app, create a function.php under Common and put the public function

function test(){
   echo 'this is a test';
}
Copy after login

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

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

3. Execute the following command in the project directory

composer dump-autoload
Copy after login

Related recommendations: Latest Five Laravel video tutorials

The above is the detailed content of How to set global method in laravel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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