New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Unique validation error #22
Comments
Hi @robsonrk! Unique is one of the validators which work differently on the frontend than the backend: https://laraform.io/docs/1.x/basics/validation#rule-unique. The reason for this is security, so the only way to use it is to separate the frontend and backend rules. Here's an example:
Laraform.config({
endpoints: {
validators: {
unique: // your endpoint, .eg 'validate/unique'
}
}
})
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
class ValidatorController extends Controller
{
public function unique(Request $request) {
switch ($request->params[0]) {
case 'user_email':
$validator = Validator::make($request->all(), [
'value' => 'unique:users,email',
]);
return response()->json(!!$validator->fails());
break;
}
}
} Hope this helps! |
Thank you for reply. I understood your explanation and I've read the documentation also. But shouldn't this work out of box as Laraform have it's own validator?
Rather, it throws an undefined index('attributes') exception at following line: |
Yes, it did have this feature out of the box, but it was removed for security reasons. The controller you've found is just a leftover which should be removed with the next release. I'd recommend going with a similar solution I've described above. |
Prerequisites
Versions
Description
Can't validate trough Laraform default unique validation.
Steps to Reproduce
Expected behavior:
Should return error message from unique validation
Or nothing if email address isn't registered yet.
Actual behavior:
Console returns an error from backend:
Additional Information
The text was updated successfully, but these errors were encountered: