Displaying the Total Count of Each Table in Laravel using Eloquent
Am working on a System where the Admin has 3 Tables, Product, User and Staff and What am trying to achieve is this: When the Admin logs in, He sees the Total Count of each Tables Example: Total Product: 89, Total Users: 1098, Total Staff: 564 Please How can I achieve this What Controller Function do I need to Write and How do I pass it to the View? Thanks
I personally store counts in an array, so I’m not having to bind many variables to a view. If I want the count from 12 models, I don’t want to be binding 12 variables to my view.
$totals = [
'articles' => Article::count(),
'comments' => Comment::count(),
'events' => Event::count(),
// And so on
];
return view('admin.dashboard', compact('totals'));
THEN ON THE VIEW (Views/public/pages/admin.blade) I echoed $pinCount like this {{ $pinCount }} but I received an error message: Undefined variable: pinCount (View: C:\wamp\www\secureserver\app\views\public\pages\admin.blade.php)
@jlrdw I meant array as in if I wanted the counts from multiple models. If I add each model’s count to an array, I just have to bind that single array to my view, rather than a variable per model.