Skip to content

Make snowflake integer castable #15

@diego-lipinski-de-castro

Description

Is your feature request related to a problem? Please describe.
Yes, I am using inside a laravel application, and cant do relationships, fails at line 1287

$value = (int) ($value instanceof BackedEnum ? $value->value : $value);

File: laravel/framework/src/Illuminate/Database/Query/Builder.php

Describe the solution you'd like
Be able to cast snowflake to int

Describe alternatives you've considered
It works if i stop casting account_id to snowflake, but I dont think thats ideal

Additional context
Code example:

// account model
class Account extends Model
{
    use HasFactory;
    use SoftDeletes;
    use HasSnowflakes;

    protected $fillable = [
        'wallet_id',
        'bank_id',
        'name',
        'balance',
    ];

    protected $casts = [
        'id' => Snowflake::class,
        'wallet_id' => Snowflake::class,
    ];
...

// card model
class Card extends Model
{
    use HasFactory;
    use SoftDeletes;
    use HasSnowflakes;

    protected $fillable = [
        'account_id',
        'brand_id',
        'name',
        'limit',
        'digits',
        'digital',
        'credit',
        'international',
    ];

    protected $casts = [
        'id' => Snowflake::class,
        'account_id' => Snowflake::class,
        'digital' => 'boolean',
        'credit' => 'boolean',
        'international' => 'boolean',
    ];
....

// controller
$cards = Card::query()
            ->ofWallet(auth('web')->user()->currentWallet)
            ->with([
                'account' => function ($query) {
                    $query->with([
                        'bank',
                    ]);
                },
                'brand',
            ])
            ->get();
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions