![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/dceprojects.corals.io/Corals/modules/ProjectPlan/Import/ |
<?php namespace Corals\Modules\ProjectPlan\Import; use Corals\Modules\ProjectPlan\Http\Requests\HotelRequest; use Corals\Modules\ProjectPlan\Models\Hotel; use Corals\Modules\ProjectPlan\Services\HotelService; class HotelImporter implements \Corals\Modules\ProjectPlan\Contracts\ModelImportContract { public function getValidationRules(): array { return [ 'name' => 'required|unique:pp_hotels', 'phone' => 'nullable|required_without_all:email,address', 'email' => 'nullable|email|required_without_all:phone,address', 'address' => 'nullable' ]; } public function getData($record): array { $phone = data_get($record, 'phone', ''); if ($phone) { $phone = getFormattedPhoneNumber($phone); } return [ 'name' => data_get($record, 'name'), 'email' => data_get($record, 'email'), 'phone' => $phone, 'address' => data_get($record, 'address'), ]; } public function saveData($data): void { $name = $data['name']; $hotelModel = Hotel::query()->where('name', $name)->first(); $hotelRequest = new HotelRequest(); $hotelRequest->replace($data); $hotelService = new HotelService(); if ($hotelModel) { $hotelService->update($hotelRequest, $hotelModel); } else { $hotelService->store($hotelRequest, Hotel::class); } } }