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

How to set global method in laravel

青灯夜游
青灯夜游Original
2021-09-23 18:07:222707browse

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';
}

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

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

3. Execute the following command in the project directory

composer dump-autoload

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!

Statement:
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