Home >PHP Framework >Laravel >How to create a function in laravel
How to create functions in laravel: 1. Create a Common folder in the app directory; 2. Create a custom function file; 3. Write a custom function method; 4. Register a custom function file; 5. Just call the custom function.
The operating environment of this article: Windows 7 system, Laravel version 5.2, DELL G3 computer.
How to create a function in laravel?
laravel creates a custom function:
The laravel version currently used is 5.2.*
1, create a Common file in the app directory Folder
2, create a custom function file in the folder Common just created, such as helpers, php
3, write a custom function method in the custom function file, For example:
if ( !function_exists( 'p' ) ) { function p( $data ) { echo "<pre class="brush:php;toolbar:false">"; print_r($data); echo ""; } }
4, register the just customized function file
if(file_exists(DIR . '/../app/Common/helpers.php')) { require DIR . '/../app/Common/helpers.php'; }
5 in the autoload.php file in the bootstrap directory in the root directory, and now you can use it anywhere in the project Call your custom function
Recommended learning tutorials: "laravel" "The latest five Laravel video tutorials"
The above is the detailed content of How to create a function in laravel. For more information, please follow other related articles on the PHP Chinese website!