Skip to content

Instantly share code, notes, and snippets.

@mknparreira
Last active August 12, 2021 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mknparreira/3c9e32ea3228033ac60ea41ca94127b3 to your computer and use it in GitHub Desktop.
Save mknparreira/3c9e32ea3228033ac60ea41ca94127b3 to your computer and use it in GitHub Desktop.
Laravel | Creating a Singleton pattern
//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); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment