There's no way to do that. An exists
statement returns a boolean. That's what the exists
rule does.
The best thing you can do here, in my opinion is removing the exists
rule from the validator, and just after the validation passes, you query for the invite. If it returns null
, then manually handle the abort()
.
$validator = Validator::make($request->all(), [
'invite' => 'required|max:30',
]);
if ($validator->fails()) {
return redirect('some/route')
->withErrors($validator)
->withInput();
}
// now check for existance
else if (! $invite = Invite::where('code', $request->code)->first()) {
return abort(404, 'Invitation not found');
}
$invite->someMethod();