//AppServiceProvider
$this->app->singleton('FooBar', function ($app) {
return $app;
});
//Anywhere
$this->app->instance('FooBar', ['name' => 'Maikon', 'age' => 15]);
//Do something with this value
$value = app()->make('FooBar');
dd($value);
Last active
August 12, 2021 22:17
-
-
Save mknparreira/3c9e32ea3228033ac60ea41ca94127b3 to your computer and use it in GitHub Desktop.
Laravel | Creating a Singleton pattern
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/davejamesmiller/bd857d9b0ac895df7604dd2e63b23afe