$book = array('book1','book2');$book 数组元素编号是可变的.它可能有 2 个元素或 20 个元素
我需要进行这样的查询:
$book = array('book1','book2');
$book array elements numbers are variable. it might have 2 element or 20 elements
I need to make a query like this:
select * from book where bookname like %book1% or bookname like %book2%
要在 Laravel 5 中进行此查询,有一个选项:
To make this query in laravel 5 there is an option :
$name = DB::Table('bookinfo')
->select('*')
->wherein('bookname',$book)
->get();
但它使用 =
运算符我需要使用 like
运算符
but it use =
operator I need to use like
operator
感谢大家帮助我,但我通过这样做解决了:
Thanks everyone for helping me but i solved it by doing:
$book = array('book2','book3','book5');
$name = DB::Table('bookinfo')
->select('BookName', 'bookId')
->Where(function ($query) use($book) {
for ($i = 0; $i < count($book); $i++){
$query->orwhere('bookname', 'like', '%' . $book[$i] .'%');
}
})->get();
这篇关于laravel querybuilder 如何在 where 函数中使用 like的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!