I'm using SQLite with Laravel and find it quite annoying that all values are returned as strings. Is there a way to enable automatic type casting (like the MySQL native driver [mysqlnd] does)?
I know about the $casts
attribute, I'm looking for an app-independent solution to make the database driver do the casting.
Thanks!
Yes, you can automatically cast. Add this property to your model.
protected $casts = [
'is_admin' => 'boolean',
'count' => 'integer'
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With