Warm tip: This article is reproduced from stackoverflow.com, please click
laravel laravel-6

Where is a "global bootstrap place" in Laravel

发布于 2020-04-10 16:13:34

I am trying to install kylekatarnls/business-day package into Laravel 6. The docs say to "First load the mixin in some global bootstrap place of your app:". Where do I put this code?

Questioner
jgravois
Viewed
19
brice 2020-02-02 06:18

One option is to place this in the boot method of your AppServiceProvider.

<?php

namespace App\Providers;

use Cmixin\BusinessDay;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $additional_holidays = [
            // ...
        ];

        BusinessDay::enable(\Illuminate\Support\Carbon::class, 'us-national', $additional_holidays);
    }
}

Another option is to create your own Service Provider and place the code in the new service provider's boot method.