select("u.contact_id", "r.is_sent", "u.created_date", "u.phone", "u.name", "u.email") ->leftjoin("raphiwa_send as r", "r.to", "u.phone") //->wherein("u.phone", ["9720692366","7310790572","9997341855","7417823793","8954762406"]) ->where("u.created_date", '>=', date("Y-m-d H:i:s", strtotime("now")-(60*15) )) ->where("r.session_id", 0) //->limit(1) ->get(); $not_received = []; foreach($records as $record) { if(!isset($record->is_sent)) { $not_received[] = $record->phone.'-'.$record->name; $rsdata = ['to' => $record->phone, 'text' => json_encode(['countryCode'=>'+91','phoneNumber'=>$record->phone,'callbackData'=>rand(10000,99999).'-'.$record->contact_id,'type'=>'Template','template'=>['name'=>'paramedic_course_registration_success','languageCode'=>'en','bodyValues'=>[$record->name,$record->contact_id] ] ]), 'is_sent' => 0, 'session_id' => 0, 'contact_id' => $record->contact_id, 'status' => 1 ]; DB::table("raphiwa_send")->insert($rsdata); // print_r($rsdata); } } print_r($not_received); exit; } }