mardi 3 avril 2018

Laravel query in if cause

I run the below query in this query, if cause true then where cause is apply like below, but when i run below query it gives me "Out of memory (allocated 503316480) (tried to allocate 492834816 bytes)" error, So another easy way to check the where cause above if condition.

Here below is my code.

$user_id = "";
$doctor_id = "";
$start_date = "";
$end_date = "";

if(isset($request->user_id)) {
    $user_id = $request->user_id;
}
if(isset($request->doctor_id)) {
    $doctor_id = $request->doctor_id;   
}
if(isset($request->start_date)) {
    $start_date = $request->start_date; 
}
if(isset($request->end_date)) {
    $end_date = $request->end_date; 
}

$query = DB::table('request_approves')
            ->join('city_masters', 'request_approves.city_id', '=', 'city_masters.id')
            ->join('doctors', 'request_approves.doctor_id', '=', 'doctors.id')
            ->select('doctors.*','city_masters.*','request_approves.*');

            if($user_id !== "") {
                $query->where('request_approves.user_id', 2);                        
            }

            if($doctor_id !== "") {
                $query->where('request_approves.doctor_id',3);    
            }

            if($start_date !== "" & $end_date !==""){
                $query->whereBetween('request_approves.approve_time', array($start_date,$end_date));    
            }
            $query->get();



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

Aucun commentaire:

Enregistrer un commentaire