Repository navigation
Conversation
|
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 ;)
} |
|
@mjauvin can this be merged? |
|
@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 |
|
@LukeTowers any objection in merging this? There's a PR to the docs also in the description. |
|
@LukeTowers Also running into this, could this be merged please? 🙏🏻 |
|
@mjauvin does this match any other scope method calls in the core? Seems somewhat arbitrary for your specific use case. @JonasPardon @AIC-BV can you provide examples of how you're using it? |
|
@LukeTowers concrete case from our webshop plugin (running patched in production since January): An product:
type: recordfinder
list: ~/plugins/aic/webshop/models/product/columns.yaml
variant:
type: recordfinder
list: ~/plugins/aic/webshop/models/variant/columns.yaml
scope: whereProductpublic function scopeWhereProduct($query, $model, $formData = [])
{
$productId = array_get($formData, 'product') ?: $model->product_id;
return $query->where('product_id', $productId); // null => empty list, forces picking a product first
}Same shape as Marc's country → state: any parent → child recordfinder pair hits this. And since PHP ignores extra arguments on userland methods, existing single-argument scopes keep working unchanged. |
|
@LukeTowers answering your Aug 26 question — yes: "call the model scope with one extra contextual argument" already has multiple precedents in the core, and The audit (your first question). Greping every dynamic method call on query builders in
So the PR makes The repro (your second question, "how you're using it"). @AIC-BV's Jan-posted
Backwards compatibility. Also verified in the same run: a scope with the old 2-arg signature One docs note for PR #256: the examples use |
Co-authored-by: Héctor pavez <hectzimudec@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughWhen Priority: ➖ Normal Estimated code review effort: 1 (Trivial) | ~3 minutes Merge Risk: ⚪ Minimal · up to RecordFinder scopes can now filter using current form data, including unsaved values. The fallback and existing scope-call compatibility are supported by the inspected implementation, with no concrete issue preventing merge. Pre-merge checks |
|

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:
Summary by CodeRabbit