0

I'm new at Voyager and I wanted to to format some numbers to a currency format. Normally, I'd do it like

//In a blade file {{ $number_format($product->price, 0, ',', '.') }}

If I want to format the displayed data in a BREAD view, how should be my JSON string to achieve my purpose?

grizzthedj
  • 7,131
  • 16
  • 42
  • 62
mito
  • 61
  • 8

1 Answers1

2

You can make use of Eloquent accessors.

In your instance, this might look like:

<?php

    namespace App;

    use Illuminate\Database\Eloquent\Model;

    class Product extends Model
    {
        /**
         * Get the product's price.
         *
         * @param  string  $value
         * @return string
         */
        public function getPriceAttribute($value)
        {
            return number_format($value, 0, ',', '.');
        }
    }
Sam
  • 2,540
  • 2
  • 23
  • 24