Skip to content
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

[7.x] Apply model connection name to Database validation rules #33525

Merged
merged 2 commits into from
Jul 13, 2020
Merged

[7.x] Apply model connection name to Database validation rules #33525

merged 2 commits into from
Jul 13, 2020

Conversation

stevebauman
Copy link
Contributor

@stevebauman stevebauman commented Jul 13, 2020

This change applies the connection name (if it is not null) to database validation rules, where a Model class is given.

This really helps when working with multiple databases in the same application and having to create rules on models that do not use the default application connection.

Without this change:

use App\Sqlsrv\Transaction;
use Illuminate\Validation\Rule;

$model = new Transaction;

$rule = implode('.', [$model->getConnectionName(), $model->getTable()]);

Rule::exists($rule, 'id');

With this change:

use App\Sqlsrv\Transaction;
use Illuminate\Validation\Rule;

Rule::exists(Transaction::class, 'id');

If the connection name is null on the model, the connection name is not applied. There is no BC break with this change.

Please let me know if anything needs to be modified for styling rules. Thanks!

This change applies the connection name (if it is not null) to database rules.

This really helps when working with multiple databases in the same application and having to create rules on non-default models.
@stevebauman stevebauman changed the title Apply model connection name to Database validation rules [7.x] Apply model connection name to Database validation rules Jul 13, 2020
@taylorotwell taylorotwell merged commit 3a50114 into laravel:7.x Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants