I am cleaning up my code which I wrote as a hopeless noob.
I am creating a view with user statistics. My intention is to make a table showing both site and user stats, for instance:
Our repository has **1000** quotes **120** of them are contributed by you.
I have several models such as Book, Quotation, Excerpt etc. To display the above, I define in my controller multipe variables
$userCountQuotes = count(Quote::where('creator_id','=',$userid)->get());
$CountQuotes = count(Quote::get());
and then pass them this way
return View::make('userworkspace.stats', compact('userCountQuotes','CountQuotes'))
I have about 10 different models to serve - 20 variables. Is there a more elegant way to get the numbers and display them in view?
My own solution: create a two-dimensional array of values
$stats= array
(
array("Books",22,18),
array("Quotes",15,13)
...
);
and then I have only one variable to pass to my view. Is that elegant enough? Any better ideas?