How to add helpers.php to laravel framework? (Detailed steps)

01-28-2024

What this article brings to you is about how to add helpers.php to laravel's framework. (Detailed steps), it has certain reference value, and friends in need can refer to it, hoping to help you.

1. create the app/Http/helpers.php file.

2. Modify the compose.json file.

"autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/" }, # Added files key "files": [ "app/Http/helpers.php" ] },

3. Execute the command composer dump-autoload.

4. Define the method in app/http/helpers.php.

if (! function_exists('test')) { function test() { # code something } }

Then, we can easily use the method directly in the program ...

public function testHelper(){ $testHelper = test(); }

Related recommendations:

The establishment of php Laravel framework background folder II

Laravel 5 framework learning model, controller, view basic process, Laravel framework

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us