S
S
sybille2020-12-17 18:41:18
Laravel
sybille, 2020-12-17 18:41:18

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

3 answer(s)
V
Vladimir Kokhan, 2020-12-17
@SkazochNick

In the AppServiceProvider in the boot method you receive data and then pass it to the necessary templates

S
Sergey delphinpro, 2020-12-17
@delphinpro

Use ViewComposer and bind data to the required or to all views in it.

T
the5x, 2020-12-17
@the5x

https://stackoverflow.com/questions/28608527/how-t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question