There is a posting from 2016 that describes how to implement Yasumi: https://www.yasumi.dev/ into Laravel. But this looks like it completely outdated now. What is the correct way to implement it into Laravel 9?
Post I am referencing from 2016: https://stackoverflow.com/a/41266340/8207054
I am using this code (AppServiceProvider):
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Carbon\Carbon;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('yasumi', \Yasumi\Yasumi::create('USA', Carbon::now()->format('Y')));
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
}
but it causes this error: Illuminate\Container\Container::bind(): Argument #2 ($concrete) must be of type Closure|string|null
CodePudding user response:
You can send function as the second parameter to singleton method like this:
$this->app->singleton('yasumi', function () {
return \Yasumi\Yasumi::create('USA', Carbon::now()->format('Y'));
});