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/clinic.corals.io/app/Repositories/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/clinic.corals.io/app/Repositories/ServicesRepository.php
<?php

namespace App\Repositories;

use App\Http\Controllers\AppBaseController;
use App\Models\Doctor;
use App\Models\Service;
use App\Models\ServiceCategory;
use DB;
use Exception;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;

/**
 * Class ServicesRepository
 * @package App\Repositories
 * @version August 2, 2021, 12:09 pm UTC
 */
class ServicesRepository extends AppBaseController
{
    /**
     * @var array
     */
    protected $fieldSearchable = [
        'category_id',
        'name',
        'charges',
        'doctors',
        'status'
    ];

    /**
     * Return searchable fields
     *
     * @return array
     */
    public function getFieldsSearchable()
    {
        return $this->fieldSearchable;
    }

    /**
     * Configure the Model
     **/
    public function model()
    {
        return Service::class;
    }

    /**
     * @param  array  $input
     *
     * @return bool
     */
    public function store(array $input): bool
    {
        try {
            DB::beginTransaction();

            $input['charges'] = str_replace(',', '', $input['charges']);
            $input['status'] = (isset($input['status'])) ? 1 : 0;
            $services = Service::create($input);
            if (isset($input['doctors']) && !empty($input['doctors'])) {
                $services->serviceDoctors()->sync($input['doctors']);
            }
            if (isset($input['icon']) && !empty('icon')) {
                $services->addMedia($input['icon'])->toMediaCollection(Service::ICON, config('app.media_disc'));
            }
            DB::commit();
            return true;
        } catch (Exception $e) {
            DB::rollBack();
            throw new UnprocessableEntityHttpException($e->getMessage());
        }
    }

    /**
     * @param $input
     * @param $service
     * @return bool
     */
    public function update($input, $service): bool
    {
        try {
            DB::beginTransaction();
            $input['charges'] = str_replace(',', '', $input['charges']);
            $input['status'] = (isset($input['status'])) ? 1 : 0;
            $service->update($input);
            $service->serviceDoctors()->sync($input['doctors']);

            if (isset($input['icon']) && ! empty('icon')) {
                $service->clearMediaCollection(Service::ICON);
                $service->media()->delete();
                $service->addMedia($input['icon'])->toMediaCollection(Service::ICON, config('app.media_disc'));
            }
            
            DB::commit();
            return true;
        } catch (Exception $e) {
            DB::rollBack();
            throw new UnprocessableEntityHttpException($e->getMessage());
        }
    }

    /**
     * @return array
     */
    public function prepareData()
    {
        $data['serviceCategories'] = ServiceCategory::orderBy('name', 'ASC')->pluck('name', 'id');
        $data['doctors'] = Doctor::with('user')->get()->where('user.status', true)->pluck('user.full_name', 'id');

        return $data;
    }
}

Spamworldpro Mini