77use Illuminate \Support \Collection ;
88use Illuminate \Database \Eloquent \Relations \Relation ;
99use Illuminate \Database \Eloquent \Relations \BelongsTo ;
10- use Illuminate \Database \Eloquent \Relations \MorphToMany ;
1110use Illuminate \Database \Eloquent \Relations \HasOneOrMany ;
12- use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
1311
1412class RelationFinder
1513{
@@ -18,21 +16,20 @@ class RelationFinder
1816 *
1917 * @param string $model
2018 * @return Collection
19+ * @throws \ReflectionException
2120 */
2221 public function getModelRelations (string $ model )
2322 {
2423 $ class = new ReflectionClass ($ model );
2524
26- $ traitMethods = Collection::make ($ class ->getTraits ())->map (function ($ trait ) {
25+ $ traitMethods = Collection::make ($ class ->getTraits ())->map (function (ReflectionClass $ trait ) {
2726 return Collection::make ($ trait ->getMethods (ReflectionMethod::IS_PUBLIC ));
2827 })->flatten ();
2928
3029 $ methods = Collection::make ($ class ->getMethods (ReflectionMethod::IS_PUBLIC ))
3130 ->merge ($ traitMethods )
3231 ->reject (function (ReflectionMethod $ method ) use ($ model ) {
33- return $ method ->class !== $ model ;
34- })->reject (function (ReflectionMethod $ method ) use ($ model ) {
35- return $ method ->getNumberOfParameters () > 0 ;
32+ return $ method ->class !== $ model || $ method ->getNumberOfParameters () > 0 ;
3633 });
3734
3835 $ relations = Collection::make ();
@@ -46,13 +43,22 @@ public function getModelRelations(string $model)
4643 return $ relations ;
4744 }
4845
46+ /**
47+ * @param string $qualifiedKeyName
48+ * @return mixed
49+ */
4950 protected function getParentKey (string $ qualifiedKeyName )
5051 {
5152 $ segments = explode ('. ' , $ qualifiedKeyName );
5253
5354 return end ($ segments );
5455 }
5556
57+ /**
58+ * @param ReflectionMethod $method
59+ * @param string $model
60+ * @return array|null
61+ */
5662 protected function getRelationshipFromMethodAndModel (ReflectionMethod $ method , string $ model )
5763 {
5864 try {
0 commit comments