-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Explicit Model in Database Validations dont work #30726
Comments
This seems to be related to a misconfiguration of the given model. Also, you would need to specify what column to query against. |
Could you provide some more information about this? I have been having similar issues. I wrote a more comprehensive explanation in the pull request.
This is incorrect - if you don't specify a column, the docs state that it will by default query the column with the same name as the input key (i.e. an input named 'email' will query the 'email' column if you don't specify a custom one). |
Hi, Take a closer look at the code and I think the problem is here: I also found that there are only tests for the Rule class. This makes me think that this PR was intended only for the use of the Rule class. And that may indicate that the documentation has an error. |
Hey there, I would love to investigate this issue further. Do you have an example application you can share that will replicate this issue? - or even a unit test against the framework? |
@ahinkle There are a fair few routes, as per my comment on the PR: option 1 is using validation rules as a single string delimited by a pipe | (notated by "delimited"), option 2 is using validation rules as strings in an array (notated by "array") and option 3 is using the exists/unique rules as instances of the class (notated by "instance"). For complete transparency I've also included examples where the column is explicitly defined as opposed to implied by the rule's name (notated by "explicit"). Options 1 and 2 both produce the same output:
Option 3 produces the expected output, given the database is in-memory and hasn't been migrated:
As you can see, option 3 correctly resolves the table name. |
PR was merged. |
@driesvints thanks |
Description:
Documentation says I can do something like the following:
email' => 'unique:App\User,email_address'
But I do a simple test and it fails!
Steps To Reproduce:
Test:
/** @test */
public function it_check_unique_validation()
{
$user = factory(User::class)->create();
Result:
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lara6
.app\user' doesn't exist
The text was updated successfully, but these errors were encountered: