auditionadmin/app/Rules/UniqueFullNameAtSchool.php

44 lines
1.1 KiB
PHP

<?php
namespace App\Rules;
use App\Models\Student;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class UniqueFullNameAtSchool implements ValidationRule
{
protected $first_name;
protected $last_name;
protected $school_id;
public function __construct($firstName, $lastName, $schoolID)
{
$this->first_name = $firstName;
$this->last_name = $lastName;
$this->school_id = $schoolID;
}
public function passes($attributies, $value)
{
return Student::where('first_name', $this->first_name)
->where('last_name', $this->last_name)
->where('school_id', $this->school_id)
->exists();
}
public function message()
{
return "There is already a student with that name at the school you are trying to add them to";
}
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
//
}
}