I am new to Laravel, and I try to validate a request. I have to following request class:
namespace App\Http\Requests;
class TestRequest extends FormRequest
{
protected function rules()
{
return [
'group_id' => 'required|exists:groups,id,deleted_at,NULL|exists:group_users,group_id,user_id,' . \Auth::user()->id
];
}
}
My problem is:
- I have to check that the group exists and it's not deleted. This is the first "exists" rule.
- And I have to check that the currently logged in user is part of the group. The second "exists" rule.
My question is:
- When any of the 2 exists fails, how do I know whitch one failed?
- I want to return a different error message for these exists checks. How should I do it?
- Do I have to write a custom validation for this?
PS: I'm using Laravel 5.3