Skip to content

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 ;)
}

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.

3 participants