petrogromovo Posted May 12, 2023 Share Posted May 12, 2023 Working with money in php 8 /laravel 9 site for money fields I use integer in mysql db and custom cast app/Casts/MoneyCast.php like : <?php namespace App\Casts; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; class MoneyCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes) { return round(floatval($value) / 100, 2); } public function set($model, string $key, $value, array $attributes) { return floatval($value) * 100; } } It seems quite good for me, but I found some referance to libraries https://github.com/brick/money andhttps://github.com/akaunting/laravel-money and wonder if some of which library is preferable for working in laravel ? Would it be better or safer ? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/316295-how-better-to-work-with-money-on-mysql-laravel-site/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.