问答 / 3 / 11 / 创建于 2年前
如何让 whereIn 里面的数字 不被转成字符串
laravel 实际执行的时候不会转换成字符串,你打印的 sql 应该是通过替换占位符生成的,统一转成了字符串
class Post extends Model { /** * The attributes that should be cast. * * @var array<string, string|class-string> */ protected $casts = [ 'transaction_id' => 'int', ]; }Copy
class Post extends Model { /** * The attributes that should be cast. * * @var array<string, string|class-string> */ protected $casts = [ 'transaction_id' => 'int', ]; }
我是这样弄的, 应该是可以的
超过数字的最大值就只能字符了吧
如果是 MySQL 的话,没什么影响呐。
列是数字类型,值是字符串,不会有啥影响呐,反过来会有影响。
在 database config 里加 PDO::ATTR_STRINGIFY_FETCHES => false
PDO::ATTR_STRINGIFY_FETCHES => false
->whereIn('id', [1, Db::raw('2')])
我要举报该,理由是:
推荐文章: