gpt4 book ai didi

php - 两个 wheres 和一个 orWhere Laravel 条件

转载 作者:行者123 更新时间:2023-11-29 06:00:02 25 4
gpt4 key购买 nike

我想在列表中搜索并只获得带有 id 的结果,但是在标题中搜索并在描述中搜索,我不需要标题和描述我想要标题或描述,但是通过这种方式我得到所有结果巧合description not limited for the first condition id, 问候。

public function search_list( Request $request ){

$id = $request->input("id_search");

$data = $request->input("search");

$lists = Lists::where( 'lists.id_user', $id )
->where( "title", "like", "%".$data."%" )
->orwhere( "description", "like", "%".$data."%" )
->paginate( 10 );

return view( 'user.lists.list_lists' )
->with( "lists", $lists )
->with( "data", $data );

}

最佳答案

使用where() closure :

Lists::where(function ($q) use ($id, $data) {
$q->where('lists.id_user', $id)
->where('title', 'like', '%' . $data . '%');
})
->orwhere('description', 'like', '%' . $data . '%')
->paginate(10);

关于php - 两个 wheres 和一个 orWhere Laravel 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45742834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com