<?php
 
namespace App\Rules;

use App\Models\Goliath\GoliathRegion;
use Illuminate\Contracts\Validation\Rule;
use Exception;

class RegionIdentity implements Rule
{

    public function passes($attribute, $value)
    {

        if (!is_scalar($value)) {
            return false;
        }

        try {
            return GoliathRegion::find($value) !== null;
        }
        catch(Exception $ex) {
            return false;
        }

    }

    public function message()
    {
        return 'The :attribute must correlate to a valid region.';
    }
}