Answer the question
In order to leave comments, you need to log in
How to correctly display information of a specific table on all pages of a Laravel site?
Good afternoon! Laravel started learning recently, so a seemingly simple question arose.
My info table contains information about the site, name, phone numbers, links to social networks. accounts, a short description, etc.
now, when creating all the methods that display the frontend, I extract all the data into the $info variable by id 1 (because there is only one record in the table) and display it on the website $info->title $info -phone and so on
$info = $this->infoRepository->getEdit(1);
Logically, I need this data on almost all pages of the site.
The question is how to correctly display this data using Laravel;
Answer the question
In order to leave comments, you need to log in
Greetings.
Do this - in the AppServiceProvider file in the boot () method, write:
view()->composer('*', function($view){
$view->with('info', TableName::find(1));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question