Hi, I have been approaching Laravel for a few days. My simple question, considering that I have done various tests, but nothing, is how can I recover in the "Controller" a function created in the "Model" (which is located in the App /, if I'm not mistaken, isn't it?), And then show it in the views?
Let me explain better, I have to show the total of my posts (as a number), then I create a query in the model that counts the total of the posts, once this is done I create the instance in the controller and pass it to the view.
Probably I'm wrong in the syntax, I attach an example:
App/Post.php
public function totalActivePost() { $count = DB::table('post')->get(); return $count->count(); }
App/Http/Controllers
$modelPost = new Post; $totalActivePost = $modelPost->totalActivePost();
return view('index',
['totalActivePost' => $totalActivePost]
);
While in the view I call then {{ @totalActivePost }}
Unfortunately nothing, what am I wrong?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community