我正在尝试获取搜索结果,并且我有以下代码:
public function search(Request $request){
$from = $request->from;
$to = $request->to;
$word = $request->word;
if(empty($word) || $word == null){
$searched = Post::whereBetween('created_at', [$from, $to])->paginate(10);
} elseif(!empty($word) && !empty($from) && !empty($to)){
$searched = Post::where('title', 'LIKE', '%' . $word . '%')
->orWhere('content', 'LIKE', '%' . $word . '%')
->orWhere('subtitle', 'LIKE', '%' . $word . '%')
->whereBetween('created_at', [$from, $to])
->paginate(10);
} elseif(empty($from) && empty($to) && !empty($word)){
$searched = Post::where('title', 'LIKE', '%' . $word . '%')
->orWhere('content', 'LIKE', '%' . $word . '%')
->orWhere('subtitle', 'LIKE', '%' . $word . '%')
->paginate(10);
}
return view('page.search', compact('searched', 'from', 'to'));
}
第一个和第二个条件正在起作用,但最后一个条件不起作用。我在这里错过了什么或做错了什么?
MMMHUHU