php artisan make:rule CompanyPackageNotExistsRule
'company_id' => ['required','integer','exists:companies,id', new CompanyPackageNotExistsRule()],
public function passes($attribute, $value)
{
return !CompanyPackage::where('company_id', $value)->exists();
}
public function message()
{
return 'You have already purchased a package.';
}
'company_id' => ['required','integer','exists:companies,id', function ($attribute, $value, $fail) {
if (CompanyPackage::where('company_id', $value)->exists()) {
$fail('You have already purchased a package.');
}
}]