Using number_format method in Laravel

后端 未结 4 2090
傲寒
傲寒 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:29

    If you are using Eloquent, in your model put:

    public function getPriceAttribute($price)
    {
        return $this->attributes['price'] = sprintf('U$ %s', number_format($price, 2));
    }
    

    Where getPriceAttribute is your field on database. getSomethingAttribute.

提交回复
热议问题