-
Notifications
You must be signed in to change notification settings - Fork 123
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
[BUGFIX] Fix unique validation in Postgres #19
Conversation
I ran into the same problem, but using the Rule class fixed it. Rule::unique('subscribers', 'email') |
Thanks for your input @MaizerGomes, let me chat with @willselby tomorrow AM and we'll decide which approach to go with. Both seem perfectly valid, though yours is a little more verbose. Either way, I think the logic should be extracted to its own protected method within the |
You're welcome. Well, I think using the Rule class adds more readability and since it has been referenced in the official laravel documentation since version 5.3 I think is easier to understand what's going on if something goes wrong. By the way, I was trying to figure out where the property "subscriber" in the request comes from. |
…to bugfix/postgres-unique-validation
Yes, I agree. The
There's a little bit of Laravel magic going on behind the scenes here. If you take a look in
This single declaration will generate multiple routes. Because we specify When we're in a
When we do
As you can see, this method will attempt to resolve the route that is attached to our request. If a route is resolved, it'll check for any route parameters that match the given key. In our case, we're looking for a parameter called If you want to get a better visualisation of this, try doing tl;dr |
Unique validation fails on subscriber creation when using Postgres because
$this->subscriber
is an empty string.https://laracatch.com/share/d145e815-16ba-4f60-9d90-98f19c35c65a