File tree Expand file tree Collapse file tree 1 file changed +35
-2
lines changed Expand file tree Collapse file tree 1 file changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -34,16 +34,49 @@ protected function getUriParser()
34
34
* @param mixed $request
35
35
* @param array $extraParams
36
36
*/
37
- protected function addCustomParams (array $ extraParams = []): void
37
+ protected function addCustomParams (array $ extraParams = []): void
38
38
{
39
39
$ this ->originalQueryParams = $ this ->request ->query ();
40
40
41
41
$ all = $ this ->request ->all ();
42
- $ new = Helpers::array_merge_request ($ all , $ extraParams );
42
+ $ new = Helpers::array_merge_request ($ all , $ extraParams, $ this -> filterByParent () );
43
43
$ this ->request ->replace ($ new );
44
44
}
45
45
46
46
47
+ protected function filterByParent (): array
48
+ {
49
+ $ parent = $ this ->parentModel ?? null ;
50
+ if ($ parent === null ){
51
+ return [];
52
+ }
53
+
54
+ if (is_array ($ parent )) {
55
+ $ key = key ($ parent );
56
+ $ param = reset ($ parent );
57
+ }else {
58
+ $ key = strtolower (class_basename ($ parent ));
59
+ }
60
+
61
+ if ($ this ->request ->isMethod ('get ' ))
62
+ {
63
+ return [
64
+ 'filter ' => [
65
+ self ::$ model ->{$ key }()->getForeignKeyName () => $ this ->request ->route ()->originalParameter ($ param ?? $ key )
66
+ ]
67
+ ];
68
+ }
69
+
70
+ if ($ this ->request ->isMethod ('post ' ))
71
+ {
72
+ return [
73
+ self ::$ model ->{$ key }()->getForeignKeyName () => $ this ->request ->route ()->originalParameter ($ param ?? $ key )
74
+ ];
75
+ }
76
+
77
+ }
78
+
79
+
47
80
/**
48
81
* Parses our sort parameters.
49
82
*/
You can’t perform that action at this time.
0 commit comments