Skip to content

Add current form data as second argument to RecordFinder scope method#1441

Open
mjauvin wants to merge 1 commit intodevelopfrom
record-finder-scope
Open

Add current form data as second argument to RecordFinder scope method#1441
mjauvin wants to merge 1 commit intodevelopfrom
record-finder-scope

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented Jan 18, 2026

It can be useful if the record finder needs some other fields in the form to filter its values.

Related: wintercms/docs#256

E.g. fields definition:

country:
    type: dropdown

state:
    type: recordfinder
    list: $/author/plugin/models/state/columns.yaml
    scope: statesByCountry
class State extends model
{
    public function scopeStatesByCountry($query, $model, $formData)
    {
        if ($country_id = array_get($formData, 'country')) {
            $query->where('country_id', $country_id);
        }
    }
}

@mjauvin mjauvin requested a review from LukeTowers January 18, 2026 17:24
@mjauvin mjauvin self-assigned this Jan 18, 2026
@mjauvin mjauvin added the enhancement PRs that implement a new feature or substantial change label Jan 18, 2026
@AIC-BV
Copy link
Contributor

AIC-BV commented Jan 19, 2026

Works perfectly! Thanks!!!

public function scopeWhereProduct($query, $model, $formData)
{
    if ($productId = array_get($formData, 'product')) {
        return $query->where('product_id', $productId);
    }
    return $query->where('product_id', null); // returns an empty list in my case, so they will be forced to select a product first ;)
}

@AIC-BV
Copy link
Contributor

AIC-BV commented Mar 10, 2026

@mjauvin can this be merged?
I had trouble because I ran composer update

@mjauvin
Copy link
Member Author

mjauvin commented Mar 10, 2026

@AIC-BV did you test this PR as well?

@AIC-BV
Copy link
Contributor

AIC-BV commented Mar 10, 2026

@AIC-BV did you test this PR as well?

I copied the change to my local file and deployed it in production since Jan 18
Works perfectly

@mjauvin
Copy link
Member Author

mjauvin commented Mar 10, 2026

@LukeTowers any objection in merging this? There's a PR to the docs also in the description.

@mjauvin mjauvin added this to the 1.2.13 milestone Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement PRs that implement a new feature or substantial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants