Pagination 使用原始查询的Laravel分页

Pagination 使用原始查询的Laravel分页,pagination,laravel-8,Pagination,Laravel 8,当我把分页(50);它显示不存在null的位置。然后我将whereNull设置为ctrl+/ 它会显示下一行OrderBy不存在。我真的不知道问题出在哪里。。因为我想在不使用DB::raw查询中的datatable的情况下进行分页 public function searchParticipation(Request $request){ ini_set('memory_limit','2G'); if ($request->method() != 'POST') {

当我把分页(50);它显示不存在null的位置。然后我将whereNull设置为ctrl+/

它会显示下一行OrderBy不存在。我真的不知道问题出在哪里。。因为我想在不使用DB::raw查询中的datatable的情况下进行分页

 public function searchParticipation(Request $request){

    ini_set('memory_limit','2G');

    if ($request->method() != 'POST') {
        return redirect()->route('ticketparticipation.view');
    }

    $replaceStartDate = $this->remove_string($request['start_date']);
    $replaceEndDate = $this->remove_string($request['end_date']);

    $valStartDate = strtotime($replaceStartDate) + (60*60*8);
    $valEndDate = strtotime($replaceEndDate) + (60*60*24) + (60*60*8) - 1;

    $event_id = $request['event_id'];
    $category_id = $request['category_id'];
    $ticket_number = $request['ticket_number'];
    $full_name = $request['full_name'];

    $dataEvent = array(
        'event_id' => $event_id,
        'category_id' => $category_id,
        'ticket_number' => $ticket_number
    );

    $superadmins = User::UserOrganizer()->get();

    $user_id = Session::get('user_id');
    $roles = Session::get('roles');

    if(empty(Session::get('roles'))){
        auth()->logout();
        return redirect('/admin/logout2');
    }

    $eventx = Event::query();

    $eventx = $eventx->select('id', 'name');

    if ($roles == 'Organizer-Admin') {
        $eventx->Where('admin_id','=',$user_id);
        $event = $eventx->Where('is_deleted','=','0')->get(); //->Where('is_active','=','1')
    }elseif($roles == 'Organizer-Project'){
        $eventx->Where('project_manager_id','=',$user_id);
        $event = $eventx->Where('is_deleted','=','0')->get(); //->Where('is_active','=','1')
    }elseif($roles == 'Organizer-Super-Admin'){
        $eventx->Where('superadmin_id','=',$user_id);
        $event = $eventx->Where('is_deleted','=','0')->get(); //->Where('is_active','=','1')
    }elseif($roles == 'Superadmin-Organizer'){
        $event = $eventx->Where('is_deleted','=','0')->get(); //->Where('is_active','=','1')
    }


    $data = array(
        'user_id' => $user_id,
        'roles' => $roles,
        'date_start' => $request['start_date'],
        'date_end' => $request['end_date']
    );

    if($data['roles'] == 'Organizer-Admin'){
        $field = "event.admin_id";
    }elseif($data['roles'] == 'Organizer-Project'){
        $field = "event.project_manager_id";
    }else{
        $field = "event.superadmin_id";
    }

    $tCount = EventParticipation::Select('event_participation.id')
        ->join('event', 'event.id', '=', 'event_participation.event_id')
        ->join('categories', 'categories.id', 'event_participation.run_id');
    if($event_id != ''){
        $tCount = $tCount->Where("event_participation.event_id", "=", $event_id);
    }
    if($category_id != ''){
        $tCount = $tCount->Where("event_participation.run_id", "=", $category_id);
    }
    if($ticket_number != ''){
        $tCount = $tCount->Where(DB::raw('concat(event.ticket_number_prepend,"",event_participation.queue_id)') , '=' , $ticket_number);
    }
    if($full_name != ''){
        $tCount = $tCount->Where("event_participation.full_name", 'LIKE' , '%'.$full_name.'%');
    }

    $tCount = $tCount->Where("event_participation.acceptance_date", "<>", 0)
        ->Where("event_participation.is_participating", "=", 1)
        ->Where("event_participation.is_deleted", "=", 0)
        ->OrderBy('event_participation.creation_date','ASC')
        ->get();


    $eventDetail = Event::Select('name', 'registration_end', 'type','primary_currency')->Where('id', '=', $event_id)->first();

    if($tCount->count() < 10000) {

        $ticketParticipation = EventParticipation::Select(
            DB::raw("if(epu.full_name is not null, epu.full_name, event_participation.full_name) as full_name"),
            DB::raw("if(epu.address is not null, epu.address, event_participation.address) as address"),
            DB::raw("if(epu.city is not null, epu.city, event_participation.city) as city"),
            DB::raw("if(epu.postcode is not null, epu.postcode, event_participation.postcode) as postcode"),
            DB::raw("if(epu.state is not null, epu.state, event_participation.state) as state"),
            DB::raw("if(epu.country is not null, epu.country, event_participation.country) as country"),
            DB::raw("if(epu.additional_info is not null, epu.additional_info, event_participation.additional_info) as additional_info"),
            'event_participation.id', 'event_participation.delivery_company', 'event_participation.tracking_number', 'event_participation.run_id','event_participation.event_id', 'event_participation.local_transaction_number', 'event_participation.user_id',
            'event_participation.nric_passport', 'event_participation.gender', 'event_participation.tshirt_size', 'event_participation.nationality',
            'event_participation.email', 'event_participation.contact_number', 'event_participation.emergency_contact_name', 'event_participation.emergency_contact_number', 'event_participation.medical_conditions', 'event_participation.amount',
            'event_participation.after_discount', 'event_participation.discount_id', 'event_participation.payment_type', 'event_participation.remarks',
            'event.name AS eventname', 'event.ticket_number_prepend', 'categories.title AS run_title', 'event_participation.date_of_birth', 'event_participation.creation_date', 'event_participation.acceptance_date',
            DB::raw("FROM_UNIXTIME(`event_participation`.`creation_date`,\"%d-%m-%Y %h:%i:%s %p\") AS `register_date`"),
            DB::raw("CONCAT(event.`ticket_number_prepend`, '', event_participation.`queue_id`) AS `ticket_number`"),
            'virtual_parcel_shipping_order.awb_id','virtual_parcel_shipping_order.awb_url','virtual_parcel_shipping_order.tracking_url','virtual_parcel_shipping_order.shipping_status',
            'virtual_parcel_shipping_order.pick_up_date','virtual_parcel_shipping_order.parcel_content',
            'virtual_parcel_shipping_order.status','virtual_parcel_shipping_order.response')//DB::raw("FROM_UNIXTIME(`event_participation`.`date_of_birth`,\"%d-%m-%Y\") AS `dob`"),
        ->join('event', 'event.id', '=', 'event_participation.event_id')
            ->join('categories', 'categories.id', 'event_participation.run_id')
            ->leftjoin('event_participation_report_status','participation_id','event_participation.id')
             ->leftjoin('virtual_parcel_shipping_order','participant_id','event_participation.id')
             ->leftjoin('event_participation_utf8 as epu', 'event_participation.id', 'epu.participation_id')->paginate(50);  <<<<<<<< got problem when I add in paginate(50)
        if($event_id != ''){
            $ticketParticipation = $ticketParticipation->Where("event_participation.event_id", "=", $event_id);
        }
        if($category_id != ''){
            $ticketParticipation = $ticketParticipation->Where("event_participation.run_id", "=", $category_id);
        }
        if($ticket_number != ''){
            $ticketParticipation = $ticketParticipation->Where(DB::raw('concat(event.ticket_number_prepend,"",event_participation.queue_id)') , '=' , $ticket_number);
        }
        if($full_name != ''){
            $ticketParticipation = $ticketParticipation->Where("event_participation.full_name", 'LIKE' , '%'.$full_name.'%');
        }

        $ticketParticipation = $ticketParticipation->Where("event_participation.acceptance_date", "<>", 0)
            ->Where("event_participation.is_participating", "=", 1)
            ->Where("event_participation.is_deleted", "=", 0)
            ->WhereNull("event_participation_report_status.participation_id")
            ->OrderBy('event_participation.queue_id', 'DESC')
            ->get()->chunk(1000);

        $eventDiscount = EventDiscountCode::Select('id', 'event_id', 'amount', 'code')->Where('event_id', $event_id)->get();
        
        return view('admin.organizer.participant_summary',['ticketParticipation'=>$ticketParticipation], compact('event', 'ticketParticipation', 'eventDiscount', 'dataEvent', 'eventDetail'));
    }else{

        return view('admin.organizer.participant_summaryv2', compact('event','data', 'dataEvent', 'eventDetail'));

    }

}
公共功能搜索参与(请求$Request){
ini_集合(“内存限制”,“2G”);
如果($request->method()!='POST'){
return redirect()->route('ticketparticipation.view');
}
$replaceStartDate=$this->remove_字符串($request['start_date']);
$replaceEndDate=$this->remove_字符串($request['end_date']);
$valStartDate=strottime($replaceStartDate)+(60*60*8);
$valEndDate=strottime($replaceEndDate)+(60*60*24)+(60*60*8)-1;
$event_id=$request['event_id'];
$category_id=$request['category_id'];
$ticket_number=$request['ticket_number'];
$full_name=$request['full_name'];
$dataEvent=array(
'event\u id'=>$event\u id,
'category\u id'=>$category\u id,
“票号”=>$票号
);
$superadmins=User::UserOrganizer()->get();
$user_id=Session::get('user_id');
$roles=Session::get('roles');
if(空(会话::get('roles')){
auth()->注销();
返回重定向('/admin/logout2');
}
$eventx=Event::query();
$eventx=$eventx->select('id','name');
如果($roles==‘组织者管理员’){
$eventx->Where('admin\u id','=',$user\u id);
$event=$eventx->Where('is_deleted'、'='、'0')->get();//->Where('is_active'、'='、'1'))
}elseif($roles=='Organizer Project'){
$eventx->Where('project\u manager\u id','=',$user\u id);
$event=$eventx->Where('is_deleted'、'='、'0')->get();//->Where('is_active'、'='、'1'))
}elseif($roles=='Organizer Super Admin'){
$eventx->Where('superadmin\u id','=',$user\u id);
$event=$eventx->Where('is_deleted'、'='、'0')->get();//->Where('is_active'、'='、'1'))
}elseif($roles=='Superadmin-Organizer'){
$event=$eventx->Where('is_deleted'、'='、'0')->get();//->Where('is_active'、'='、'1'))
}
$data=数组(
'user\u id'=>$user\u id,
“角色”=>$roles,
'date\u start'=>$request['start\u date'],
'date\u end'=>$request['end\u date']
);
如果($data['roles']=='Organizer Admin'){
$field=“event.admin\u id”;
}elseif($data['roles']=='Organizer Project'){
$field=“event.project\u manager\u id”;
}否则{
$field=“event.superadmin\u id”;
}
$tCount=EventParticipation::Select('event\u participation.id')
->加入('event','event.id','=','event\u participation.event\u id'))
->加入('categories','categories.id','event_participation.run_id');
如果($event_id!=''){
$tCount=$tCount->Where(“event\u participation.event\u id”、“=”、$event\u id);
}
如果($category_id!=''){
$tCount=$tCount->Where(“事件参与.运行id”、“=”、$category\U id);
}
如果($ticket_number!=''){
$tCount=$tCount->Where(DB::raw('concat(event.ticket\u number\u prepend,“,event\u participation.queue\u id)”),'=',$ticket\u number);
}
如果($full_name!=''){
$tCount=$tCount->Where(“event\u participation.full\u name”、'LIKE'、'%.$full\u name.'%');
}
$tCount=$tCount->Where(“事件参与.接受日期”,“0”)
->式中(“事件参与。是否参与”、“=”、1)
->其中(“已删除事件参与度,”=”,0)
->订购人('event\u participation.creation\u date','ASC')
->get();
$eventDetail=Event::Select('name'、'registration_end'、'type'、'primary_currency')->Where('id'、'=',$Event_id)->first();
如果($t计数->计数()<10000){
$ticketParticipation=EventParticipation::Select(
DB::raw(“如果(epu.full_name不为null,epu.full_name,event_participation.full_name)作为full_name”),
DB::raw(“如果(epu.address不为null,epu.address,event_participation.address)作为地址”),
DB::raw(“如果(epu.city不为空,epu.city,event_participation.city)作为城市”),
DB::raw(“如果(epu.postcode不为空,epu.postcode,event_participation.postcode)作为邮政编码”),
DB::raw(“如果(epu.state不为null,epu.state,event_participation.state)作为状态”),
DB::raw(“如果(epu.country不为空,epu.country,event_participation.country)作为国家”),
DB::raw(“如果(epu.additional\u info不为空,epu.additional\u info,event\u participation.additional\u info)作为additional\u info”),
“事件参与.id”,“事件参与.交付公司”,“事件参与.跟踪编号”,“事件参与.运行id”,“事件参与.事件id”,“事件参与.本地事务处理编号”,“事件参与.用户id”,
“活动参与。nric护照”、“活动参与。性别”、“活动参与。T恤尺寸”、“活动参与。国籍”,
“事件参与.电子邮件”,“事件参与.联系电话”,“事件参与.紧急联系人姓名”,“事件参与.紧急联系人号码”,“事件参与.医疗状况”,“事件参与.金额”,
“活动参与.折扣后”,“活动参与.折扣id”,“活动参与.付款类型”,“活动参与.备注”,
“event.name作为eventname”、“event.ticket\u number\u prepend”、“categories.title作为run\u title”、“event\u participation.日期作为event\u出生日期”、“event\u participation.创建日期”、“event\u participation.验收日期”,
DB::raw(“从UNIXTIME(`event\u participation`.`creation\u date`,\%d-%m-%Y%h:%i:%s%p\”)作为`register\u date`),
DB::raw(“CONCAT(事件.'ticket\u number\u prepend`,'',事件参与.'queue\u id`)作为'ticket\u number`,”,
“虚拟包裹装运订单.awb\U id”,“虚拟包裹装运订单.awb\U url”,“虚拟包裹装运订单.跟踪url”,“虚拟包裹装运订单.s”