我试图在我的控制器中添加日期搜索过滤器,但始终显示错误"功能名称必须是字符串" 附加图片。
注意:我的控制器已经有2个工作搜索过滤器,其中一个是搜索框第二个是下拉列表
控制器:
public function index(Request $request)
{
//this for search box
$search=$request->input('search');
// this for drop down list
if(request()->has('lead_status')){
$leads=Lead::where('lead_status', request('lead_status'))
->paginate(5)
->appends('lead_status',request('lead_status'));
}
// this for date search from and to
if($search()->has('from') && $search()->has('to'))
{
$from_date = date('Y-m-d', strtotime($search()->has('from')));
$to_date = date('Y-m-d', strtotime($search()->has('to')));
$leads = Lead::whereBetween('created_at', [$from_date, $to_date]);
}
else{
$leads=Lead::orderBy('created_at','desc')->search($search)->paginate(5);
}
return view ('leads.index')->with('leads',$leads);
}