我想将此查询转换为Laravel 4 Eloquent。
$query = SELECT * FROM standard_products WHERE frame_category like "%1%" OR
frame_category like "%2%" OR frame_category like "%3%";
这里我有一个阵列
$frame = Array([1]=1,[2]=2,[3]=3);
要求:
使用$frame
数组,我希望在Laravel-Eloquent 中得到相同的结果
我的努力是:
foreach ($frame as $val) {
$match = Standard_product::orWhere('frame_category','like','%'.$val.'%');
}
$match = $match->get()->toArray();
但CCD_ 2和CCD_。请帮我转到
您可以像一样进行
Model::where(function ($query) use ($frame) {
foreach($frame as $val){
$query->orWhere('frame_category','like',"%$val%");
}
})->get();
$frame = Array(1,2,3);
$q = DB::table('standard_products');
foreach ($frame as $val) {
$q = $q->orWhere('frame_category','like','%'.$val.'%');
}
生成
select *
from `standard_products`
where `frame_category` like ?
or `frame_category` like ?
or `frame_category` like ?