I have a singleton setup in my AppServiceProvider.php
, such as this:
public function boot()
{
$this->app->singleton(Breadcrumbs::class, function($app){
return new Breadcrumbs();
});
View::composer(['partials.*'], function($view){
$view->with('breadcrumbs', new Breadcrumbs());
});
}
Breadcrumbs is just a simple class that manages an array of breadcrumbs and I want there only to be 1 object across the whole app (so every time you call new Breadcrumbs()
you actually get the existing object, not a new one. (i think this is what singletons are for?)
But now have added this to the JetStreamServiceProvider.php
public function boot()
{
$this->configurePermissions();
Fortify::loginView(function (){
$breadcrumbs = new Breadcrumbs();
$breadcrumbs->add('login','login.php');
return view('auth.login');
});
}
However instead of using the same object as what was created in the AppServiceProvider it is making a new object (so the breadcrumbs object in AppServiceProvider and the breadcrumbs object in the JetStreamServiceProvider are 2 different objects containing a different set of data)...which is no good.
What am I doing wrong?