File "ValidateDate.php"

Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Rules/ValidateDate.php
File size: 736 bytes
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Rules;

use Carbon\Carbon;
use Illuminate\Contracts\Validation\InvokableRule;

class ValidateDate implements InvokableRule
{
    public function __invoke($attribute, $value, $fail)
    {
        if ($attribute == 'date_scheduled')
            $message = 'The date scheduled can not be weekend.';
        else if ($attribute == 'delivery_date')
            $message = 'The delivery date can not be weekend.';
        else
            $message = 'The date pick up / ship by can not be weekend.';

        try {
            $date = Carbon::make($value);
            if ($date->isWeekend()) $fail($message);
        } catch (\Exception $e){
//            $fail('The :attribute is not a valid date.');
        }
    }
}