我想将此查询转换为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();
但$match
的结果不等于$query
。请帮帮我
答案 0 :(得分:3)
你可以像
那样做 <div class="tab-nav">
<?php while ($row1 = mysql_fetch_array($result1)) : ?>
<a href="vacancies.php?id=<?php $row1['id']; ?>" class="active"><?php $row1['name']; ?></a>
<?php endwhile ?>
</div>
答案 1 :(得分:2)
$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 ?