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/ts.corals.io/corals-api/Corals/modules/Timesheet/Http/Requests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Http/Requests/ActivityRequest.php
<?php

namespace Corals\Modules\Timesheet\Http\Requests;

use Corals\Foundation\Http\Requests\BaseRequest;
use Corals\Modules\Timesheet\Models\Activity;
use Corals\Modules\Utility\Facades\ListOfValue\ListOfValues;

class ActivityRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $this->setModel(Activity::class);

        return $this->isAuthorized();
    }

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

        if ($this->isUpdate() || $this->isStore()) {
            $rules = array_merge($rules, [
                'title' => 'required',
                'description' => '',
                'billable' => '',
                'hourly_rate' => 'nullable|numeric|min:0',
            ]);

            if ($this->get('is_limited')) {
                foreach (ListOfValues::get('positions') as $key => $position) {
                    $rules['properties.' . $key] = 'required|min:0';
                }
            }
        }

        if ($this->isStore()) {
            $rules = array_merge($rules, [
            ]);
        }

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

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

        return $rules;
    }

    public function attributes()
    {
        $attributes = [
            'title' => trans('Timesheet::attributes.activity.title'),
            'description' => trans('Timesheet::attributes.activity.description'),
            'billable' => trans('Timesheet::attributes.activity.billable'),
            'hourly_rate' => trans('Timesheet::attributes.activity.hourly_rate'),
        ];

        foreach (ListOfValues::get('positions') as $key => $position) {
            $attributes['properties.' . $key] = $position;
        }

        return $attributes;
    }


    /**
     * @return \Illuminate\Contracts\Validation\Validator
     */
    public function getValidatorInstance()
    {
        $data = $this->all();

        if ($this->isStore() || $this->isUpdate()) {
            $data['billable'] = data_get($data, 'billable') ?? 0;
            $data['is_active'] = data_get($data, 'is_active') ?? 0;
            $data['is_limited'] = data_get($data, 'is_limited') ?? 0;
            $data['is_special'] = data_get($data, 'is_special') ?? 0;
            $data['properties'] = data_get($data, 'properties') ?? [];

            if (!$data['is_limited']) {
                foreach (ListOfValues::get('positions') as $key => $position) {
                    unset($data['properties'][$key]);
                }
            }

            $this->getInputSource()->replace($data);
        }

        return parent::getValidatorInstance();
    }
}

Spamworldpro Mini