Reputation: 5491
I want to check if the user ID is different than the id of the owner of the group, so that user can't remove owner from the group.
Validation looks like this:
$this->validate($request, [
'user_id' => 'required
|numeric
|different:'.$group->owner.'
|exists:group_user,user_id,group_id,'.$group->id.'
|exists:users,id',
]);
Unfortunately, it fails no matter what value I put or what's the value of 'user_id'.
Error message:
The user id and 1 must be different.
Thanks
Upvotes: 1
Views: 1061
Reputation: 769
This is what the authorization feature of Laravel is useful for. You will create a gate that will make this check for you, and return an error if the check fails. The validation you are using is more making sure inputs match the correct format, or are included if required.
Upvotes: 1