Get the App
SLTechnology News&Howtos  ›  Development  › 

How laravel creates functions

Shulou Source: shulou.com Published: 2022-06-03 19:44:22 09月13日 Update

This article mainly shows you "laravel how to create functions", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to create functions in laravel" this article.

Laravel create function method: 1, create Common folder in app directory; 2, create file custom function file; 3, write custom function method; 4, register custom function file; 5, call custom function.

This article operating environment: windows7 system, Laravel5.2 version, DELL G3 computer.

How does laravel create a function?

Laravel creates a custom function:

The current version of laravel is 5.2.*

1, create a Common folder in the app directory

2. Create custom function files such as helpers,php in the folder Common you just created

3. Write custom function methods in custom function files, such as:

If (! function_exists ('p')) {function p ($data) {echo "; print_r ($data); echo";}}

4. Register the function file you just customized in the autoload.php file in the bootstrap directory in the root directory

If (file_exists (DIR. '/.. / app/Common/helpers.php') {require DIR. '/.. / app/Common/helpers.php';}

5, you can now call your custom function anywhere in the project

These are all the contents of the article "how to create functions in laravel". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Functions files contents folders methods directories articles learning help location easy to understand more organization root directory version environment computer knowledge system tape Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia MariaDB Huawei OPPO Reno