Laravel ada validasi
'state_id' => 'exists:states,id'
Lokesh003
'state_id' => 'exists:states,id'
$e = Subscription::find($request->subscription_id);
$rules = [
'subscription_id' => 'required|integer|exists:subscriptions,id',
'date' => 'required|date|after:yesterday',
'date' => Rule::unique('member_attendances')->where(function ($query) use ($e) {
return $query->where('member_id', $e->member_id);
})
//|unique:member_attendances,date,'.$e->member_id . ',member_id',
];
//create a rule if you're going to use it again
php artisan make:rule CompanyPackageNotExistsRule
//FormRequest
'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.';
}
//or use directly
'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.');
}
}]