简体   繁体   English

在Laravel 5.5中使用whereInStrict()

[英]Using whereInStrict() in laravel 5.5

I tried using whereIn() in my project but because of its loose comparison it considered a value '1gb' as integer. 我尝试在项目中使用whereIn() ,但由于比较宽松,因此将值“ 1gb”视为整数。 So as per the documentation I used whereInStrict() . 因此,根据文档,我使用whereInStrict()

$spec['vals'] = ['1 gb', '2gb', '8gb']; // array created by explod()     
ProductSpecification::whereInStrict('value', $spec['vals'])->get();

But the creates sql query like "Select * from product_specifications where in_strict = 'value' " , thus giving an error. 但是创建sql查询,例如“从product_specifications中选择*,其中in_strict ='value'” ,从而产生错误。 What to do? 该怎么办? Am I using it wrong? 我使用错了吗?

I'm kinda new to laravel. 我是laravel的新手。

You need to have a collection of the ProductSpecification , so first get all and then use whereInStrict . 您需要具有ProductSpecification的集合,因此首先获取全部,然后使用whereInStrict

$spec['vals'] = ['1 gb', '2gb', '8gb'];
ProductSpecification::all()->whereInStrict('value', $spec['vals']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM