Support the ongoing development of Laravel.io →
posted 8 years ago
Views Blade
Last updated 2 years ago.
0

Pretty sure that's not a laravel problem but simply php.

What you say in your first line is "Assign the value 100 to the variable completed and then count that variable" which will work since it will always be 1. The second line says "see if completed is smaller than 100 and then count the boolean value that this produces". Also completed is not the collection.

What you need is something like this:

"filter $tasks to only get tasks with completed == true and count those".

Should be something like

{{ count($tasks->where("completed", true)) }}
0

Uhm... first of all thx for your help. But in my db the 'completed' column is integer (tasks table). It report the working status of the task from 0% to 100% and I need to show something like:

Completed (2) / In progress (5)

0

Ah, now I get it.

{{ $tasks->where("completed", 100)->count() }}

That should give you the completed ones.

{{ $tasks->filter(function ($item) { return $item->completed < 100;})->count() }}

That should give you the In progress ones. I took that from the laravel 5.1 documentation, I hope those methods already exist in 5.0. http://laravel.com/docs/5.1/collections

Last updated 8 years ago.
0

It works thanks.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

reficul reficul Joined 26 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.