open-admin-org / open-admin

open-admin forked from z-song/laravel-ladmin. Removing jquery, now based on Bootstrap5, vanilla JS
https://open-admin.org
MIT License
245 stars 71 forks source link

How to display the Custom cast column? #152

Open sd-evo opened 7 months ago

sd-evo commented 7 months ago

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?

RCyrix commented 7 months ago

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

sd-evo commented 7 months ago

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?

RCyrix commented 7 months ago

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

sd-evo commented 7 months ago

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.

RCyrix commented 7 months ago

I am unable to assist here.