open-admin icon indicating copy to clipboard operation
open-admin copied to clipboard

How to display the Custom cast column?

Open sd-evo opened this issue 2 years ago • 5 comments

I have custom cast class, which return MoneyPhp object. Laravel doc: https://laravel.com/docs/10.x/eloquent-mutators#custom-casts My code:

$grid->column('current_balance', __('admin.grid.wallet.current_balance'))->display(function ($value) {
    $decimalFormatter = new DecimalMoneyFormatter(new ISOCurrencies());

    return $decimalFormatter->format($value);
});

I get error:

Снимок экрана от 2024-02-05 03-19-28

How to display the column which using Custom cast?

sd-evo avatar Feb 05 '24 00:02 sd-evo

cast it as a string.. it expects a string value.

RCyrix avatar Feb 05 '24 09:02 RCyrix

cast it as a string.. it expects a string value.

Thanks for answer!

But I specifically use Custom cast to MoneyPhp in the application. I have app and open admin panel. I can't to use the string type. Any ideas?

sd-evo avatar Feb 05 '24 13:02 sd-evo

grid is only display, it doesnt submit data, only "views" data, the form would handle data submission

RCyrix avatar Feb 05 '24 15:02 RCyrix

grid is only display, it doesnt submit data, only "views" data, the form would handle data submission

Yes, but grid expects that the field "current_balance" is string... How I can show this data type(MoneyPhp) in grid using method "display"? Strict typing is the best practice, so I use custom cast to MoneyPhp in Eloquent.

sd-evo avatar Feb 05 '24 20:02 sd-evo

I am unable to assist here.

RCyrix avatar Feb 06 '24 05:02 RCyrix