Answer the question
In order to leave comments, you need to log in
How to pass model to all views with __construct?
Controller from which everything is inherited
public $new_comments_moderate;
public function __construct()
{
$this->categories = $categories;
$this->companies_modal = $companies_modal;
$comments_count = CompaniesComment::query()
->where('status', 0)
->count();
$this->new_comments_moderate = $comments_count;
}
{{$new_comments_moderate}}
return view('admin.dashboard')->with([
'new_comments_moderate' => $this->new_comments_moderate
]);
Answer the question
In order to leave comments, you need to log in
The correct option was suggested to you above by JhaoDa, to start a provider, extract and forward data to the desired template via View:: compose. The code that you stuck in the controller constructor smells, it doesn't belong there.
But if you need a quick and crooked crutch, you can View::share('new_comments_moderate', $this->new_comments_moderate);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question