File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace Kettasoft \Filterable \Traits ;
44
5+ use Illuminate \Support \Arr ;
6+
57trait InteractsWithRelationsFiltering
68{
79 /**
@@ -55,6 +57,32 @@ public function getRelations(): array
5557 return $ this ->relations ;
5658 }
5759
60+ /**
61+ * Check if the given path is a valid relation path.
62+ *
63+ * @param string $path
64+ * @return bool
65+ */
66+ public function hasRelationPath (string $ path )
67+ {
68+ if (str_contains ($ path , '. ' )) {
69+
70+ $ relations = explode ('. ' , $ path );
71+
72+ $ field = array_pop ($ relations );
73+
74+ $ path = implode ('. ' , $ relations );
75+
76+ if (Arr::isAssoc ($ this ->relations )) {
77+ return isset ($ this ->relations [$ path ]) && in_array ($ field , $ this ->relations [$ path ]);
78+ }
79+
80+ return in_array ($ relations [0 ], $ this ->relations );
81+ }
82+
83+ return false ;
84+ }
85+
5886 /**
5987 * Create Filterable instance with define relations attributes.
6088 * @param array $relations
You can’t perform that action at this time.
0 commit comments