E
E
Evgeny Elchev2014-10-08 01:17:05
Laravel
Evgeny Elchev, 2014-10-08 01:17:05

Laravel how to load data from database for layout?

Hello! There is a template, it has a layout in which it is necessary to load data from the database. It is necessary to do this on all pages of the site, so loading them on each route is stupid. But the question arises, where to download them in this case? The base controller comes to mind from which I inherit all of my controllers. But I don’t know how to transfer data from the base controller to the layout. Tell me how to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
naneri, 2014-10-10
@rsi

I ran into this problem myself a couple of weeks ago.
To do this, there is View::share();
He automatically passes a variable to all views, even if you don’t know in advance which one.

V
Vyacheslav Plisko, 2014-10-08
@AmdY

There are different ways:
1. Spaghetti code, select data directly in the template.
2. Through filters
3. Through events
4. laravel.com/docs/4.2/responses#view-composers
......

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question