⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
hospital.dev-unit.com
/
app
/
Repositories
/
View File Name :
PharmacistRepository.php
<?php namespace App\Repositories; use App\Models\Address; use App\Models\Department; use App\Models\Pharmacist; use App\Models\User; use Exception; use Hash; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Class PharmacistRepository * * @version February 14, 2020, 9:32 am UTC */ class PharmacistRepository extends BaseRepository { /** * @var array */ protected $fieldSearchable = [ 'user_id', ]; /** * Return searchable fields */ public function getFieldsSearchable(): array { return $this->fieldSearchable; } /** * Configure the Model **/ public function model() { return Pharmacist::class; } public function store(array $input, bool $mail = true) { try { $input['department_id'] = Department::whereName('Pharmacist')->first()->id; $input['password'] = Hash::make($input['password']); $input['dob'] = (! empty($input['dob'])) ? $input['dob'] : null; // $input['phone'] = preparePhoneNumber($input, 'phone'); if (! empty(getSuperAdminSettingValue()['default_language']->value)) { $input['language'] = getSuperAdminSettingValue()['default_language']->value; } $input['tenant_id'] = getLoggedInUser()->tenant_id; $user = User::create($input); $pharmacist = Pharmacist::create(['user_id' => $user->id, 'tenant_id' => $input['tenant_id']]); $ownerId = $pharmacist->id; $ownerType = Pharmacist::class; if (! empty($address = Address::prepareAddressArray($input))) { Address::create(array_merge($address, ['owner_id' => $ownerId, 'owner_type' => $ownerType, 'tenant_id' => $input['tenant_id']])); } $user->update(['owner_id' => $ownerId, 'owner_type' => $ownerType]); $user->assignRole($input['department_id']); } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } return $user; } public function update($input, $pharmacist) { try { $user = User::find($pharmacist->user->id); /** @var Pharmacist $pharmacist */ $input['dob'] = (! empty($input['dob'])) ? $input['dob'] : null; // $input['phone'] = preparePhoneNumber($input, 'phone'); $pharmacist->user->update($input); $pharmacist->update($input); if (! empty($pharmacist->address)) { if (empty($address = Address::prepareAddressArray($input))) { $pharmacist->address->delete(); } $pharmacist->address->update($input); } else { if (! empty($address = Address::prepareAddressArray($input)) && empty($pharmacist->address)) { $ownerId = $pharmacist->id; $ownerType = Pharmacist::class; Address::create(array_merge($address, ['owner_id' => $ownerId, 'owner_type' => $ownerType])); } } } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } return $user; } }