Skip to content

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

@linaspasv

Description

@linaspasv
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions