Skip to content
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

groupBy should accept boolean values on Illuminate\Database\Eloquent\Collection #18672

Closed
linaspasv opened this issue Apr 5, 2017 · 1 comment

Comments

@linaspasv
Copy link
Contributor

  • Laravel Version: 5.4.16
  • PHP Version: 7.1
  • Database Driver & Version: MariaDB 10.1

Description:

I have the problem, where I need to groupBy an eloquent field that's being casted as a boolean. An expected behaviour would be to allow groupBy for boolean field where true stands for 1 and false stands for 0. Also in a regular PHP $results[true] = 'value' results to $results[1] = 'value'.

Steps To Reproduce:

Eloquent model:

/**
 * @property int $id
 * @property string $title
 * @property string|null $description
 * @property int $service_fee
 * @property bool $is_pickup
 * @property bool $is_active
 * @property int $order_to_display
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 */
class Shipment extends Model
{
    protected $table = 'shipments';
    protected $guarded = [];

    protected $casts = [
        'is_pickup' => 'boolean'
    ];
}

The following code throws an error: array_key_exists(): The first argument should be either a string or an integer :

$shipments = Shipment::all();
$shipmentsGroup = $shipments->groupBy('is_pickup');

I would be happy to make a PR for this.

@themsaid
Copy link
Member

themsaid commented Apr 5, 2017

Closing since a PR is already opened. Moving the discussion there.

@themsaid themsaid closed this as completed Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants