Reputation: 55
I want to calculate all numbers in one row from table and get the resulting in blade, how can ? i'm using Laravel 5.3? this my try:
{{ $posts = App\Post::where(['counts' => allOf()])->count() }}
and this:
{{ $posts = App\Post::orderBy('counts', '=', '*')->count() }}
but this not working
Upvotes: 1
Views: 78
Reputation: 4308
It sounds like you want the SUM of the count
?
If you are using the query builder directly you could use sum('count')
.
https://laravel.com/docs/5.3/queries#aggregates
Since you appear to be using eloquent you should use App\Post::all()->sum('count')
https://laravel.com/docs/5.3/collections#method-sum
This will gather all the posts into a collection and then sum the count field.
Edit...
Might also try App\Post::sum('count')
Upvotes: 2