File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -374,7 +374,7 @@ public function __call($method, $parameters)
374
374
return $ this ->$ method (...$ parameters );
375
375
}
376
376
377
- if (! in_array ($ method , $ allowedBuilderMethods )) {
377
+ if (! in_array ($ method , $ allowedBuilderMethods ) && ! $ this -> hasNamedScope ( $ method ) ) {
378
378
static ::throwBadMethodCallException ($ method );
379
379
}
380
380
Original file line number Diff line number Diff line change @@ -472,9 +472,38 @@ public function __call($method, $parameters)
472
472
return $ this ;
473
473
}
474
474
475
+ if ($ this ->hasNamedScope ($ method )) {
476
+ return $ this ->callNamedScope ($ method , $ parameters );
477
+ }
478
+
475
479
throw new BadMethodCallException ('Call to undefined method ' . static ::class . ":: {$ method }() " );
476
480
}
477
481
482
+ /**
483
+ * Determine if the given model has a scope.
484
+ *
485
+ * @param string $scope
486
+ *
487
+ * @return bool
488
+ */
489
+ public function hasNamedScope (string $ scope ): bool
490
+ {
491
+ return $ this ->model_class && (new $ this ->model_class )->hasNamedScope ($ scope );
492
+ }
493
+
494
+ /**
495
+ * Apply the given named scope on the current builder instance.
496
+ *
497
+ * @param string $scope
498
+ * @param array $parameters
499
+ *
500
+ * @return mixed
501
+ */
502
+ protected function callNamedScope (string $ scope , array $ parameters = [])
503
+ {
504
+ return (new $ this ->model_class )->callNamedScope ($ scope , array_merge ([$ this ], $ parameters ));
505
+ }
506
+
478
507
/**
479
508
* @inheritdoc
480
509
*/
You can’t perform that action at this time.
0 commit comments