demand
In laravel customize a number of auxiliary functions, custom functions, you want to laravel framework automatically load these functions do not need to include
achieve
1, create a custom function php files and folders, as shown below:
2, files in an autoload array compsoer.json added, the content is as follows:
PS: there must be an absolute path;
- Absolute path: Find the file from the root directory, it has been to find the file location.
- Relative path: The path relative file itself to find.
Execution composer dump-autoload -o load file
F:\laravel\yzm>composer dump-autoload -o
Generated optimized autoload files containing 3239 classes
You can now use zhang method function.php inside.
- Those steps do not define the route in detail in writing.
controller controller
class functionController extends Controller
{
//打印自定义函数
public function index(){
//include '../app/common/function.php';
zhang();
}
}