Answer the question
In order to leave comments, you need to log in
Laravel how to pass data to all controllers?
Greetings. My site has a header that is connected to almost all pages via the @include('inc.header') directive.
In this header, I need to display data from the database. What is the best way to do this? I could, for example, access the database through all the methods of my controller and only then pass data to the header, but then I would have to duplicate the code, and most likely there is some more elegant option. Waiting for your suggestions
Answer the question
In order to leave comments, you need to log in
In the AppServiceProvider in the boot method you receive data and then pass it to the necessary templates
Use ViewComposer and bind data to the required or to all views in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question