If I have a column like this 'price' as decimal, when I get this value from Database, it returns a string instead of decimal or float. How can I fix this?
CodePudding user response:
you can solve it in the whole project by casting in model
protected $casts = ['column_name' => 'type'];
example:
protected $casts = ['price' => 'float'];
documentation link: click here
CodePudding user response:
You can just do this before showing;
$price = (float)$product->price;
Or you can make a function, it will work.