/home/mip/mip/app/Modules/Client/Requests/JobOpening/JobOpeningRequest.php
<?php

namespace QxCMS\Modules\Client\Requests\JobOpening;

use Input;
use Illuminate\Foundation\Http\FormRequest;

class JobOpeningRequest 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()
    {
        return [
            'position'     => 'required|min:3|unique:client.job_opening,position,'.($this->getId() ? $this->getId() : NULL).',id',
            'no_position' => 'required|numeric|min:1',
            'min_age' => 'numeric|min:1',
            'max_age' => 'numeric|greater_than_field:min_age|min:1',
            'opening_date' => 'required',
            'closing_date' => 'required|after:opening_date',
            'status' => 'required',
            'location' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'position.required' => 'The position title field is required.',
            'no_position.required' => 'The no of applicant field is required.',
            'no_position.numeric' => 'The no of applicant must be a number.',
            'no_position.min' => 'The no of applicant field must be at least 1.',
            'max_age.greater_than_field' => 'The max age field must be greater than min age.',
        ];
    }

    public function getId()
    {
        return decode($this->job_opening);
    }
}