File "SalesComparisonRequest.php"

Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Http/Requests/Admin/SalesComparisonRequest.php
File size: 1.06 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Http\Requests\Admin;

use App\Models\ReportYearOverYear;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;

class SalesComparisonRequest extends FormRequest
{

    public function authorize()
    {
        return Gate::allows('sales_comparison_access');
    }

    public function rules()
    {
        return [
            'report_type' => [
                'nullable',
                'in:' . implode(',', array_keys(ReportYearOverYear::REPORTS_MODE))
            ],
            'year_from' => [
                'required_if:report_type,custom',
                'date_format:Y',

            ],
            'year_to' => [
                'required_if:report_type,custom',
                'date_format:Y',
                'after_or_equal:year_from',
            ],
        ];
    }

    public function messages()
    {
        return [
            'year_from.date_format' => 'The year from should be a valid 4 digit year.',
            'year_to.date_format' => 'The year to should be a valid 4 digit year.',
        ];
    }
}