Answer the question
In order to leave comments, you need to log in
How to make a global model in Laravel?
Records from a certain table are displayed on each page, and it turns out that in each controller in each action the same line is indicated:
How can this be written so that it is global or something?
I'm just starting in Laravel, not necessarily ready-made code, tell me at least which topic to watch. $lists = List::all();
Answer the question
In order to leave comments, you need to log in
Here is the answer to your question (based on another answer):
https://si-dev.com/blog/laravel-view-composers
Exhaustive and without water :)
// I was curious to know this myself ))
inside the controller you can
public $lists;
public function __construct()
{
$this->lists = List::all();
}
public function getLists()
{
return List::all();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question