Using number_format method in Laravel

后端 未结 4 2288
傲寒
傲寒 2021-02-06 22:52

I am fairly new in Laravel and Blade templating.
Can anyone help show me how to do this?

I have a view like this:

@foreach ($Expen         


        
4条回答
  •  甜味超标
    2021-02-06 23:11

    If you are using Eloquent the best solution is:

    public function getFormattedPriceAttribute()
    {
        return number_format($this->attributes['price'], 2);
    }
    

    So now you must append formattedPrice in your model and you can use both, price (at its original state) and formattedPrice.

提交回复
热议问题