May 21, 2024
0
Level 2
Error while casting as decimal with precise value
I'm trying to cast a quantity attribute in my Laravel model as a decimal with three decimal places. I have successfully used float and double casts, but I need more precise control over the decimal points. Can you help me set this up? Casts doesn't work with decimal:3. This is the same datatype I am using in mysql db.
class ProductionOrder extends Model
{
use HasFactory, HasUuids;
protected $table = 'production_orders';
protected $primaryKey = 'po_id';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'po_number',
'material_id',
'quantity',
'status',
'record_date',
'created_by',
'updated_by',
];
protected $casts = [
//'quantity' => 'double', <----- this works
'quantity' => 'decimal:3', //this doesn't
];
I am using laravel 10 on php 8.2
Please or to participate in this conversation.