K
K
Kolya Vantukh2018-03-24 21:59:17
Laravel
Kolya Vantukh, 2018-03-24 21:59:17

How to eliminate duplicate code with passing variables to blades in controllers?

The bottom line is this: the site has a header, which in fact does not change when switching between pages, and it only has a select in which you can change the language of the site. the names of languages ​​are pulled from the database. The problem is that each time I go to a new page in each controller, I need to create a variable with languages ​​and pass a blade. The problem can be in curve splitting of a template on blades? How can the problem be solved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Barmunk, 2018-03-25
@vkolya

for this use view composers
https://scotch.io/tutorials/sharing-data-between-v...

V
Vladislav Nagorny, 2018-03-24
@esvils

at the dock

$lang = ['ru','en'];
view()->share('lang',$lang);

And you put it in a hat

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question