Steps for laravel to configure global common functions



In laravel project development, common functions are often used. How to configure global common functions in laravel?? Let’s have a look at the detailed introduction

The method is as follows

In laravel project, we often need to define some global public functions, which are usually defined in a separate file, such as helpers.php. We create a file named helpers.php (APP / helpers. PHP) in the app directory, and edit its contents as follows:

 *String twice MD5 encryption
 *@ param $STR string to encrypt
function double_md5($str) {

 return md5(md5(trim($str)));

This function returns the string after MD5 encryption of a string twice. To enable the application to find the helpers.php file correctly, you need to modify the autoload configuration of composer.json under the root directory of the project:

"autoload": {
  "classmap": [
  "psr-4": {
   "App\": "app/"
  "files": [

Specify the files / folders to be loaded in the files array of the autoload configuration item. After the modification, run composer dump autoload to make sure the modification takes effect:

composer dump-autoload
A kind of
composer dumpautoload

Now that all the functions in helpers.php are loaded into the autoloader, you can use the functions defined in the helpers.php file in your project code.


The above is the whole content of this article. I hope that the content of this article has some reference learning value for your study or work. Thank you for your support for developepaer.