Composer's pot
Since the Phper have used the composer, for the traditional loading method is not used, can be described as "received East, lost roundabouts."
Let's talk about how to change the load order to overwrite the helper function in Laravel.
1. Direct require
Open the Laravel portal file index.php, you can see require __DIR__.‘/../vendor/autoload.php‘; , for example, we overwrite the Today function
You can add a helper.php to the app directory, then overwrite,
<?phpuse Carbon\Carbon;function today(){return Carbon::today("PRC")->toDateTimeString();}
Change to a string, create a new route, test it, and find that the string is returned.
2. Using Composer-include-files
Install composer require Funkjedi/composer-include-files first
Then edit the Composer.json and add the Include_files to the extra entry.
{"extra": {"include_files": [ "app/helpers.php" ]},}
Note that before you do, you have to put helper.php in the auto-add
"autoload": { "files": [ "app/helpers.php" ]}
Run composer dump, you can see in the vendor/composer/autoload_files.php, our helper.php was put to the front
PHP changes the order of automatic loading