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)
374374 return $ this ->$ method (...$ parameters );
375375 }
376376
377- if (! in_array ($ method , $ allowedBuilderMethods )) {
377+ if (! in_array ($ method , $ allowedBuilderMethods ) && ! $ this -> hasNamedScope ( $ method ) ) {
378378 static ::throwBadMethodCallException ($ method );
379379 }
380380
Original file line number Diff line number Diff line change @@ -472,9 +472,38 @@ public function __call($method, $parameters)
472472 return $ this ;
473473 }
474474
475+ if ($ this ->hasNamedScope ($ method )) {
476+ return $ this ->callNamedScope ($ method , $ parameters );
477+ }
478+
475479 throw new BadMethodCallException ('Call to undefined method ' . static ::class . ":: {$ method }() " );
476480 }
477481
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+
478507 /**
479508 * @inheritdoc
480509 */
You can’t perform that action at this time.
0 commit comments