Steps for laravel to configure global common functions

Time:2019-11-19

Preface

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": [
   "database/seeds",
   "database/factories"
  ],
  "psr-4": {
   "App\": "app/"
  },
  "files": [
   "app/helpers.php"
  ]
 },

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.

summary

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.

Recommended Today

The method of obtaining the resolution of display by pyqt5

The code is as follows import sys from PyQt5.QtWidgets import QApplication, QWidget class Example(QWidget): def __init__(self): super().__init__() self.initUI() #Interface drawing to initui method def initUI(self): self.desktop = QApplication.desktop() #Get display resolution size self.screenRect = self.desktop.screenGeometry() self.height = self.screenRect.height() self.width = self.screenRect.width() print(self.height) print(self.width) #Show window self.show() if __name__ == ‘__main__’: #Create applications and objects app […]