<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use App\Rules\ExistRule;
use EF;

class PayrollRequest extends FormRequest
{
    /**
     * 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()
    {
        EF::errorMessage('Required form validation.');

        $current_path = url()->current();

        if($current_path === url('payrollpost'))
        {
            $validation = $this->getValidationList();

            return $validation;

           
        }

       
       
   

    }

     public function getValidationList()
    {



      $payment_mode = ['Cash','Cheque','Online'];
       $mode_list = implode(',', $payment_mode);

          return [

            'user_id.*'                   =>   ['required', new ExistRule('users','id')],

            'minute_sheet_id'             =>   ['required', new ExistRule('minute_sheets','id')],

            'bank'                        =>   ['required', new ExistRule('accounts','id',false)],

            'payment_mode.*'               =>   'required|In:'.$mode_list,     

            

          ];

    }
    
}
