S
S
suhuxa12017-08-10 11:19:43
Laravel
suhuxa1, 2017-08-10 11:19:43

How to organize the output of the same information for different pages in laravel?

Probably the title was not clear enough. The point is this. I have a view template, traditionally divided into sections. There is a footer.php file, which, of course, is responsible for the footer. The footer displays information from the database. There are many pages on the site and the footer connects to all of them. Each page is rendered by a separate controller. The question is, is it really necessary to do the same thing in each controller - to make a selection from the database and transfer an array with data to the view, or can this matter be automated somehow? I really don't want to paste the same code into every controller.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Chekanov, 2017-08-10
@suhuxa1

Pass the data to all templates in the service provider. In the boot method write view()->share(variable_name, variable_value);

I
imhuman, 2017-08-10
@imhuman

https://laravel.com/docs/5.4/views#view-composers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question