This repository was archived by the owner on Jul 31, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -19,9 +19,30 @@ private function getIndexName(Model $model)
1919 return $ model ->getTable ();
2020 }
2121
22- private function hasAlgoliaTrait (Model $ model )
22+ private function hasAlgoliaTrait (Model $ class , $ autoload = false )
2323 {
24- return (isset (class_uses ($ model )['AlgoliaSearch\Laravel\AlgoliaEloquentTrait ' ]));
24+ $ traits = [];
25+
26+ // Get traits of all parent classes
27+ do {
28+ $ traits = array_merge (class_uses ($ class , $ autoload ), $ traits );
29+ } while ($ class = get_parent_class ($ class ));
30+
31+ // Get traits of all parent traits
32+ $ traitsToSearch = $ traits ;
33+ while (!empty ($ traitsToSearch )) {
34+ $ newTraits = class_uses (array_pop ($ traitsToSearch ), $ autoload );
35+ $ traits = array_merge ($ newTraits , $ traits );
36+ $ traitsToSearch = array_merge ($ newTraits , $ traitsToSearch );
37+ };
38+
39+ foreach ($ traits as $ trait => $ same ) {
40+ $ traits = array_merge (class_uses ($ trait , $ autoload ), $ traits );
41+ }
42+
43+ $ traits = array_unique ($ traits );
44+
45+ return (isset ($ traits ['AlgoliaSearch\Laravel\AlgoliaEloquentTrait ' ]));
2546 }
2647
2748 public function isAutoIndex (Model $ model )
You can’t perform that action at this time.
0 commit comments