Home > PHP Framework > Laravel > body text

How to create a function in laravel

藏色散人
Release: 2023-01-13 00:40:23
Original
2217 people have browsed it

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.

How to create a function in laravel

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 "
"; } }
Copy after login

4, register the just customized function file

if(file_exists(DIR . &#39;/../app/Common/helpers.php&#39;))
{
require DIR . &#39;/../app/Common/helpers.php&#39;;
}
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template