mardi 27 février 2018

Laravel Query Builder with MySQL date in between

I need to inject one WHERE clause into my existing query builder. The new WHERE condition makes me stuck on how to integrate with my existing query model.

AND (rpt_content_main.dt_added BETWEEN CURDATE() - INTERVAL $duration DAY AND CURDATE())

The existing query model

$report_items = RptContentMain::with(['UsrStudentMain'])
        ->select('rpt_content_main.*','rpt_content_type.type_name')
        ->whereIn('rpt_content_main.status_action',$pzaction)
        ->where('rpt_content_main.content_type',RPT_CONTENT_TYPE_ID_FEEDBACK)
        ->where('qst_master_main.published_status',QUESTION_STATUS_PUBLISHED)
        ->leftJoin('rpt_content_type', 'rpt_content_type.type_id', '=', 'rpt_content_main.report_type_id')
        ->leftJoin('qst_master_main','qst_master_main.question_id','=','rpt_content_main.content_id')
        ->orderBy('rpt_content_main.admin_reported','asc')
        ->orderBy('rpt_content_main.report_id','desc')
        ->paginate($per_page)
        ->appends(array(
            'q' => \Request::get('q'),
            't'   => \Request::get('t'),
            'pzaction'   => \Request::get('pzaction'),
            'duration'   => \Request::get('duration'),
        ))
    ;

How I can achieve this without break my existing query model?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2Fah5E7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire