dimanche 15 décembre 2019

How to use getAttribute() method for laravel eloquant for database table filed like d_1, d_2

I have a table schema with column names like d_1, d_2,.. I want to modify that fields value before use in blade file.

I have tried laravel model method like below, but unfortunately it not worked.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ModelName extends Model
{
   public function getD1Attribute()
   {
      return (float) number_format($this->attributes['d_1'], 2);
   }
}

can any one help me with this specific case ?

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire