whereBetween 不存在,我无法应用分页

whereBetween doesnt exist and i cant apply paginate

我有这个方法:

   public function indexGuest($idAzienda, Request $request){

    $companyId = $idAzienda;
    $ddts = Ddt::where('company_id',$companyId);
    $ddt_urls= Ddt_file_url::all();

    if($request->start_date || $request->end_date){
        $ddts->whereBetween('created_at',[new Carbon($request->start_date),new Carbon($request->end_date)]);
    }
    $ddts->paginate(10);

    return view('guest.ddt-management')->with('ddts', $ddts)->with('ddt_urls',$ddt_urls)
        ->with('companyId',$companyId);


}

我的 start_dateend_date 出现在像 "yyyy-mm-dd" 这样的字符串中。 我试图将它直接传递给查询,就像在示例中一样,就像一个没有希望的碳对象!

执行查询后(现在只有一个没有 wherebeeteween 子句的查询)我无法将方法 "paginate" 应用于集合,没有引发错误但是当我将它传递给视图时,"link()" 方法不起作用并再次引发错误。 我哪里错了?

Laravel 5.4

像这样构建您的 where

public function indexGuest($idAzienda, Request $request) { 
    [...]
    $ddts = Ddt::where('company_id', $companyId)
        ->where(function($query) use ($request) {
            if($s = $request->get("start_date") {
                 $s_date = Carbon::parse($s)->format("Y-m-d");
                 $query->whereDate("created_at", ">=", $s_date);
            }
            if($e = $request->get("end_date") {
                 $e_date = Carbon::parse($e)->format("Y-m-d");
                 $query->whereDate("created_at", "<=", $e_date);
            }
        })
        ->paginate(10);     
    [...]
}