Home > Software engineering >  How this Laravel Provider works?
How this Laravel Provider works?

Time:08-16

I get the fundamentals of Service Providers in Laravel 9.X, so I followed a video on YouTube and the tutor used this code to hand out a variable to a webpage:

public function boot()
    {
        view()->composer('*', function ($view) {
            $someRandomVariable = "Hello";
            return $view->with('tests', $someRandomVariable);
        });
    }

I understand everything except the composer('*', ...) thing, anyone got a hint? It works somehow and I dont know why.

CodePudding user response:

The composer method accepts the * character as a wildcard, allowing you to attach a composer to all views:

View::composer('*', function ($view) {
    //
});

CodePudding user response:

hi !

it means that the views are loaded by composer .

you need to call composer to pass some variables before the view loaded and he used this : *

because he want to select all views.

I hope it was useful .

  • Related