Finally got an answer here: http://stackoverflow.com/questions/43822596/laravel-unique-and-exists-validation-class-does-not-exist
Damn shouldn't have paid for subscription xD
Hello, I am having a very weird issue which I do not know how to solve, I use lumen 5.4 and I am a little confused about something, I have always used these two validations like this:
$rules = [
"field1" => "required|exists:users",
"field2" => "required|unique:users"
];
$messages = [
"field1.exists" => "Lorem ipsum dolor sit amet.",
"field2.unique" => "Lorem ipsum dolor sit amet."
];
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails()) {
return response($validator->errors(), 400);
}
just like the doc says, where "users" is the name of the table in the database. However now all of a sudden I get "Error 500 Class users does not exist"
This confused me, checked the docs again and it says to use the table name, so I just assumed that there's been some update and it now uses the Model name instead so I tried that.
Thing is I have all my Models in a Models folder with the following namespace: App\Models;
So then I tried:
$rules = [
‘field1’ => "required|exists:User",
‘field2’ => "required|unique:User"
];
and
$rules = [
‘field1’ => "required|exists:\App\Models\User",
‘field2’ => "required|unique:\App\Models\User"
];
and
$rules = [
‘field1’ => "required|exists:App/Models/User",
‘field2’ => "required|unique:App/Models/User"
];
and
$rules = [
‘field1’ => "required|exists:App\\Models\\User",
‘field2’ => "required|unique:App\\Models\\User"
];
None of these worked, I have been coding in Java for a while now so it's possible that I may have forgotten my stuff and I am doing something wrong here.
Exception:
{
"message": "Class users does not exist.",
"code": -1,
"status_code: 500,
"debug": {
"line": 334,
"file": "/home/xxxxx/xxxxx/vendor/laravel-doctrine/orm/src/IlluminateRegistry.php",
"class": "ReflectionException",
"trace": [..]
}
}
I have tried using different tables, I have tried it in different controllers but still.
I posted on stackoverflow over a week ago but was not able to get a solutions or even a reason why this is happening.
Finally got an answer here: http://stackoverflow.com/questions/43822596/laravel-unique-and-exists-validation-class-does-not-exist
Damn shouldn't have paid for subscription xD
Please or to participate in this conversation.