Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: SQLite returns values as strings

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!

like image 591
Jonas Staudenmeir Avatar asked May 11 '15 21:05

Jonas Staudenmeir


1 Answers

Yes, you can automatically cast. Add this property to your model.

protected $casts = [
    'is_admin' => 'boolean',
    'count' => 'integer'
];
like image 113
Pawel Bieszczad Avatar answered Sep 21 '22 14:09

Pawel Bieszczad