lpj/app/Rules/UniqueCifExceptZero.php

26 lines
608 B
PHP
Raw Normal View History

<?php
namespace Modules\Lpj\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Modules\Lpj\Models\Debiture;
class UniqueCifExceptZero implements ValidationRule
{
public function __construct($id = null)
{
$this->id = $id;
}
public function validate($attribute, $value, $fail): void
{
if (Debiture::where($attribute, $value)
->where('id', '!=', $this->id)
->where($attribute, '!=', '000000')
->exists()) {
$fail('The :attribute field must be uniquse.'.$this->id);
}
}
}