I am trying to edit the admin information using a Custom Rule, I want the admin to be able to reset her email when she edits her information but not to reset her email to others.
This is my Custom Rule checkAdminEmailExist.php, please correct it wherever there is a problem
<?php
namespace App\Rules;
use App\Repositories\Interfaces\AdminRepositoryInterface;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Auth;
class checkAdminEmailExist implements Rule
{
public AdminRepositoryInterface $admin_repository;
public function __construct()
{
$this->admin_repository = app()->make(AdminRepositoryInterface::class);
}
public function passes($attribute, $value):bool
{
if($value == Auth::user()->email) {
return true;
}
if ($this->admin_repository->checkAdminEmailExist($value)) {
return false;
}
return true;
}
public function message():string
{
return 'The :attribute duplicate';
}
}