get()->toArray(); foreach ($sants as $sant) { $thanaID = Constant::NULL; $thanaSantID = []; $thanaID = ThanaMember::where('sant_id', $sant['id'])->value('thana_id'); $thanaSantID = ThanaMember::where('thana_id', $thanaID)->pluck('sant_id'); if (!empty($sant['location'])) { // $santLocation = SantLocation::find($sant['location']['sant_id']); $santLocation = SantLocation::where('sant_id', $sant['location']['sant_id'])->first(); if (empty($santLocation)) { if (!empty($thanaSantID) && count($thanaSantID) > 0) { foreach ($thanaSantID as $santID) { SantLocation::create([ 'sant_id' => $santID, 'sangh_id' => Constant::NULL, 'type' => isset($sant['location']['to_sangh_id']) ? Constant::STATUS_TWO : Constant::STATUS_ONE, 'location' => $sant['location']['to'], 'latitude' => $sant['location']['to_latitude'], 'longitude' => $sant['location']['to_longitude'], 'created_by' => $sant['location']['created_by']['id'] ?? Constant::NULL, 'updated_by' => Constant::NULL, ]); } } else { SantLocation::create([ 'sant_id' => $sant['id'] ?? Constant::NULL, 'sangh_id' => Constant::NULL, 'type' => isset($sant['location']['to_sangh_id']) ? Constant::STATUS_TWO : Constant::STATUS_ONE, 'location' => $sant['location']['to'], 'latitude' => $sant['location']['to_latitude'], 'longitude' => $sant['location']['to_longitude'], 'created_by' => $sant['location']['created_by']['id'] ?? Constant::NULL, 'updated_by' => Constant::NULL, ]); } } else { if (!empty($thanaSantID) && count($thanaSantID) > 0) { foreach ($thanaSantID as $santID) { if ($santID == $santLocation->sant_id) { $santLocation->update([ 'sant_id' => $santID, 'sangh_id' => Constant::NULL, 'type' => $santLocation->type, 'location' => $sant['location']['to'] ?? $santLocation->location, 'latitude' => $sant['location']['to_latitude'] ?? $santLocation->latitude, 'longitude' => $sant['location']['to_longitude'] ?? $santLocation->longitude, 'created_by' => $santLocation->created_by ?? Constant::NULL, 'updated_by' => $sant['location']['created_by']['id'] ?? Constant::NULL, ]); } } } else { $santLocation->update([ 'sant_id' => $sant['id'] ?? $santLocation->sant_id, 'sangh_id' => Constant::NULL, 'type' => $santLocation->type, 'location' => $sant['location']['to'] ?? $santLocation->location, 'latitude' => $sant['location']['to_latitude'] ?? $santLocation->latitude, 'longitude' => $sant['location']['to_longitude'] ?? $santLocation->longitude, 'created_by' => $santLocation->created_by ?? Constant::NULL, 'updated_by' => $sant['location']['created_by']['id'] ?? Constant::NULL, ]); } } } } return $this->info(trans(__('Command executed successfully!'))); } catch(Exception $ex) { Log::error($ex->getMessage()); } } }