8000 Collection value() method does not return valid falsey values like '0' or 0 or false. · Issue #55722 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Collection value() method does not return valid falsey values like '0' or 0 or false. #55722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sajjadhossainshohag opened this issue May 13, 2025 · 4 comments

Comments

@sajjadhossainshohag
Copy link
Contributor

Laravel Version

12.13.0

PHP Version

8.3.13

Database Driver & Version

No response

Description

The Collection value() method fails to return falsey values such as '0', 0, or false, even when a matching item exists in the collection.

Steps To Reproduce

Route::get('test', function () {
    dd(collect([
        [
            'name' => 'currency',
            'value' => '0' // Also, false, '0'
        ],
        [
            'name' => 'currency_symbol',
            'value' => 'USD'
        ],
    ])->where('name', 'currency')->value('value'));
});


// Expected: '0'
// Actual: null
@macropay-solutions
Copy link
macropay-solutions commented May 13, 2025

Initially this returned USD because it loosely compared the value with true. Then they changed it or at least tried to. There is an issue or discussion that we can't find atm about this.

@lokeshrangani
Copy link

I believe this is an issue, as the Collection::value() method doesn't return false values like '0', 0, or false even when a match exists. I've opened a PR to address it and am open to any feedback or suggestions!

PR: #55512

@rodrigopedra
Copy link
Contributor

@macropay-solutions
Copy link
macropay-solutions commented May 13, 2025

This value method usage on a collection is not intuitive. Why are people using: get column value from a collection of rows and expect only one value and not a list of column values?

$collection->first()?->column;
would be the logic choice.

@laravel laravel locked and limited conversation to collaborators May 14, 2025
@crynobone crynobone converted this issue into discussion #55734 May 14, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0