Spamworldpro Mini Shell
Spamworldpro


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/syn.corals.io/Corals/modules/Syndicate/Services/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/syn.corals.io/Corals/modules/Syndicate/Services/PharmacistService.php
<?php

namespace Corals\Modules\Syndicate\Services;

use Corals\Modules\Syndicate\Models\Pharmacist;
use Corals\User\Services\UserService;

class PharmacistService extends UserService
{
    public function postStoreUpdate($request, &$additionalData)
    {
        /**
         * @var Pharmacist $model
         */
        $model = $this->model;

        $this->storeOrUpdateNewRecords($model, 'userAcademies', 'academies');
        $this->storeOrUpdateNewRecords($model, 'userJobs', 'jobs');
        $this->storeOrUpdateNewRecords($model, 'insuranceMembers', 'insurances');
        $this->storeOrUpdateNewRecords($model, 'beneficiaries', 'beneficiaries');

        if ($request->get('is_chairman') == 1) {
            Pharmacist::query()
                ->where('id', '<>', $model->id)
                ->update(['is_chairman' => 0]);
        }
    }

    private function storeOrUpdateNewRecords($model, $relationName, $fetchName)
    {
        $records = request()->get($fetchName, []);

        $newRecord = collect($records)->where('id', 'new-item');

        $existingRecords = collect($records)->where('id', '<>', 'new-item');

        if ($newRecord) {
            $model->$relationName()->createMany($newRecord);
        }

        foreach ($existingRecords ?? [] as $record) {
            $model->$relationName()->updateOrCreate(['id' => $record['id']], $record);
        }
    }
}

Spamworldpro Mini