Laravel Illuminate\Validation\Rule not found

hatemjapo picture hatemjapo · Nov 14, 2016 · Viewed 10.6k times · Source

I am trying to submit a form and validate the content. In one of the requests I need to make a special rule. I followed the documentation and it says to use unique and declare a Rule.

use Illuminate\Validation\Rule;

Validator::make($data, [
'email' => [
    'required',
    Rule::unique('users')->ignore($user->id),
],
]);

I am trying with the example from the documentation, but all I get it this error:

Class 'Illuminate\Validation\Rule' not found

I declared the line

use Illuminate\Validation\Rule;

In my controller, but the error is still there.

Answer

henrik picture henrik · Nov 14, 2016

You dont have to use the Rule class for this.

Simply achieve the same with following rule:

'email' => 'required|unique:users,email,' . $user->id