Reputation: 2072
I have problem with Laravel validation when validation fails it also call block of code where it should be successful...
I am trying to check for some user id if his admin_id field equal with user which is currently logged.
Here is code:
$auth = Auth::user()->id;
$inputs = array(
'id' => Input::get('id')
);
$rules = array(
'id' => "required|exists:users,id,admin_id,$auth"
);
$validate = Validator::make($inputs, $rules);
if ($validate->fails()) {
return $validate->messages()->all();
} else {
return 'succes';
}
Upvotes: 2
Views: 589
Reputation: 5649
You can do this without validation.
$auth = Auth::user()->id;
$input = Input::get('id');
if($auth != $input){
return 'your custom error message';
}else{
return 'success';
}
Upvotes: 0
Reputation: 15457
Try doing this:
$rules = array(
'id' => "required|exists:users,id,admin_id," . $auth
);
Upvotes: 1