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/medad.corals.io/Corals/modules/Medad/Http/Requests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/medad.corals.io/Corals/modules/Medad/Http/Requests/CompanyRelationRequest.php
<?php

namespace Corals\Modules\Medad\Http\Requests;

use Corals\Foundation\Http\Requests\BaseRequest;
use Corals\Modules\Medad\Constants\CompanyTypeConstants;
use Corals\Modules\Medad\Facades\Medad;
use Corals\Modules\Medad\Models\Company;
use Illuminate\Validation\Rule;

class CompanyRelationRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $this->setModel(Company::class);
        $rules = parent::rules();

        if ($this->isUpdate() || $this->isStore()) {
            $company = $this->route('company');
            $companyRelation = $this->route('companyRelation');
            $rules = array_merge($rules, [
                'branches.*' => 'exists:medad_companies,id',
            ]);
        }

        if ($this->isStore()) {
            $rules = array_merge($rules, [
                'code' => 'required',
                'name' => 'required',
                'phone_number' => 'nullable|required_without:email',
                'email' => 'nullable|email|required_without:phone_number',
                'relation_type' => [
                    'required',
                    Rule::in(CompanyTypeConstants::toArray()),
                    Rule::unique('medad_company_relation', 'relation_type')->where(
                        function ($query) use ($company, $companyRelation) {
                            return $query->where([
                                ['company_id', '=', $company->id ?? $companyRelation->company_id],
                                ['second_company_id', '=', $this->company_id]
                            ]);
                        }),
                ],
            ]);
        }

        if ($this->isUpdate()) {
            $company = $this->route('company');

            $rules = array_merge($rules, [
            ]);
        }

        return $rules;
    }

    public function messages()
    {
        return [
            'relation_type.unique' => trans('Medad::messages.validation.company_relation_exists'),
        ];
    }

    /**
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function getValidatorInstance()
    {
        if ($this->isStore()) {
            $data = $this->all();
            $data['relation_type'] = Medad::getCompanyOppositeType();
            $this->getInputSource()->replace($data);
        }

        return parent::getValidatorInstance();
    }
}

Spamworldpro Mini