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

[8.x] Adds possibility to customize child model route binding resolution #39929

Merged
merged 3 commits into from
Dec 8, 2021
Merged

Conversation

marvin-wtt
Copy link
Contributor

This is an approach to allow the user to define a custom model binding query by overwriting the added function resolveRouteBindingQuery. It is needed if lookup of the model cannot be achieved by comparing the value with the field.
The actual problem is briefly explained in #39779

For an for me unknown reason, the test models actually return a model instead of a relation. I considered this even though I don't understand the intention for that.

I am open for other ideas

@marvin-wtt
Copy link
Contributor Author

An example for localized fields where the translations are stored as JSON:

class TestModel extends Model
{
    // ...

    public function resolveRouteBindingQuery($query, $value, $field = null): Builder
    {
        return $query->where("{$field}->{$this->getLocale()}", $value);
    }
}

@iamgergo
Copy link
Contributor

iamgergo commented Dec 8, 2021

I had a similar attempt here: #34134, however it was a BC.

An addition like this, would be very handy in my opinion, thanks for the PR.

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.

3 participants