-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Exists database rule uses the wrong connection #43914
Comments
You should not set a connection name in your table name. That's not supported. |
I am not setting the connection name on the table. I am setting the database name. They are two independent things. |
@driesvints When you say "connection name" can you clarify what you're referring to?
@trovster is using the
In this instance, accessing another database on the same connection using |
Heya, setting the database name is also not supported. I don't think we document that anywhere. |
That being said. We could maybe get a fix in and get this documented if it technically works. You could try a PR with a fix and a PR to the docs? It's just that I've seen people try to use it like this in the past and they always run into edge cases because take into account that it can work like this. |
I have been looking into this further and was about to put in a PR which removes the code. But I have found the original issue which was addressed at #37580 – they seem to imply the class User extends Model {
$table = 'public.users';
}
Rule::unique(User::class) // don't work -> Database connection [public] not configured. They say they
For me the syntax is /** @var string */
protected $connection = 'connectionName'; The code to nullify the connection IF it is the same as the database name seems like an incorrect assumption. I removed the code and the tests still passed, so I am not sure they were robust enough. I am not sure how to proceed with this now. |
Description:
When using
new Exists(Model::class, 'column')
with a table name which has a database prefix fails to validate correctly when also matching the required connection name.I have two main connections; both have multiple databases so all my table names are prefixed with the database name. Adding this prefix allows relationships (via joins) to work correctly between databases on the same connection, which might have the same table name (eg
db1.users
anddb2.users
). A second connection, which is named "crm" has a database calledcrm
and thus the table names arecrm.users
.I have investigated the issue and found that removing
$connection = null;
from line #945 in ValidatesAttributes.php solves the issue. I am not sure what the condition solves, but it breaks in this scenario.Steps To Reproduce:
Set up two connections and set the default connection. The other connection should be named the same as the table database prefix (eg crm).
The text was updated successfully, but these errors were encountered: