66
77class RelationResourceRegistrar extends ResourceRegistrar
88{
9+ /**
10+ * Add the index method for a resourceful route.
11+ *
12+ * @param string $name
13+ * @param string $base
14+ * @param string $controller
15+ * @param array $options
16+ * @return Route
17+ */
18+ protected function addResourceIndex ($ name , $ base , $ controller , $ options ): Route
19+ {
20+ $ uri = $ this ->getNestedResourceUriWithoutNestedParameter ($ name , $ base );
21+
22+ unset($ options ['missing ' ]);
23+
24+ $ action = $ this ->getResourceAction ($ name , $ controller , 'index ' , $ options );
25+
26+ return $ this ->router ->get ($ uri , $ action );
27+ }
28+
29+ /**
30+ * Add the search method for a resourceful route.
31+ *
32+ * @param string $name
33+ * @param string $base
34+ * @param string $controller
35+ * @param array $options
36+ * @return Route
37+ */
38+ protected function addResourceSearch (string $ name , string $ base , string $ controller , array $ options ): Route
39+ {
40+ $ uri = $ this ->getNestedResourceUriWithoutNestedParameter ($ name , $ base ).'/search ' ;
41+
42+ $ action = $ this ->getResourceAction ($ name , $ controller , 'search ' , $ options );
43+
44+ return $ this ->router ->post ($ uri , $ action );
45+ }
46+
47+ /**
48+ * Add the store method for a resourceful route.
49+ *
50+ * @param string $name
51+ * @param string $base
52+ * @param string $controller
53+ * @param array $options
54+ * @return Route
55+ */
56+ protected function addResourceStore ($ name , $ base , $ controller , $ options ): Route
57+ {
58+ $ uri = $ this ->getNestedResourceUriWithoutNestedParameter ($ name , $ base );
59+
60+ unset($ options ['missing ' ]);
61+
62+ $ action = $ this ->getResourceAction ($ name , $ controller , 'store ' , $ options );
63+
64+ return $ this ->router ->post ($ uri , $ action );
65+ }
66+
967 /**
1068 * Add the update method for a resourceful route.
1169 *
@@ -17,7 +75,7 @@ class RelationResourceRegistrar extends ResourceRegistrar
1775 */
1876 protected function addResourceUpdate ($ name , $ base , $ controller , $ options ): Route
1977 {
20- $ uri = $ this ->getResourceUri ($ name). ' /{ ' . $ base. ' ?} ' ;
78+ $ uri = $ this ->getNestedResourceUriWithNestedParameter ($ name, $ base) ;
2179
2280 $ action = $ this ->getResourceAction ($ name , $ controller , 'update ' , $ options );
2381
@@ -35,7 +93,7 @@ protected function addResourceUpdate($name, $base, $controller, $options): Route
3593 */
3694 protected function addResourceShow ($ name , $ base , $ controller , $ options ): Route
3795 {
38- $ uri = $ this ->getResourceUri ($ name). ' /{ ' . $ base. ' ?} ' ;
96+ $ uri = $ this ->getNestedResourceUriWithNestedParameter ($ name, $ base) ;
3997
4098 $ action = $ this ->getResourceAction ($ name , $ controller , 'show ' , $ options );
4199
@@ -53,7 +111,7 @@ protected function addResourceShow($name, $base, $controller, $options): Route
53111 */
54112 protected function addResourceDestroy ($ name , $ base , $ controller , $ options ): Route
55113 {
56- $ uri = $ this ->getResourceUri ($ name). ' /{ ' . $ base. ' ?} ' ;
114+ $ uri = $ this ->getNestedResourceUriWithNestedParameter ($ name, $ base) ;
57115
58116 $ action = $ this ->getResourceAction ($ name , $ controller , 'destroy ' , $ options );
59117
@@ -71,10 +129,97 @@ protected function addResourceDestroy($name, $base, $controller, $options): Rout
71129 */
72130 protected function addResourceRestore (string $ name , string $ base , string $ controller , array $ options ): Route
73131 {
74- $ uri = $ this ->getResourceUri ($ name). ' /{ ' . $ base. ' ?} /restore ' ;
132+ $ uri = $ this ->getNestedResourceUriWithNestedParameter ($ name, $ base). ' /restore ' ;
75133
76134 $ action = $ this ->getResourceAction ($ name , $ controller , 'restore ' , $ options );
77135
78136 return $ this ->router ->post ($ uri , $ action );
79137 }
80- }
138+
139+ /**
140+ * Add the batch store method for a resourceful route.
141+ *
142+ * @param string $name
143+ * @param string $base
144+ * @param string $controller
145+ * @param array $options
146+ * @return Route
147+ */
148+ protected function addResourceBatchStore (string $ name , string $ base , string $ controller , array $ options ): Route
149+ {
150+ $ uri = $ this ->getNestedResourceUriWithoutNestedParameter ($ name , $ base ).'/batch ' ;
151+
152+ $ action = $ this ->getResourceAction ($ name , $ controller , 'batchStore ' , $ options );
153+
154+ return $ this ->router ->post ($ uri , $ action );
155+ }
156+
157+ /**
158+ * Add the batch update method for a resourceful route.
159+ *
160+ * @param string $name
161+ * @param string $base
162+ * @param string $controller
163+ * @param array $options
164+ * @return Route
165+ */
166+ protected function addResourceBatchUpdate (string $ name , string $ base , string $ controller , array $ options ): Route
167+ {
168+ $ uri = $ this ->getNestedResourceUriWithoutNestedParameter ($ name , $ base ).'/batch ' ;
169+
170+ $ action = $ this ->getResourceAction ($ name , $ controller , 'batchUpdate ' , $ options );
171+
172+ return $ this ->router ->patch ($ uri , $ action );
173+ }
174+
175+ /**
176+ * Add the batch destroy for a resourceful route.
177+ *
178+ * @param string $name
179+ * @param string $base
180+ * @param string $controller
181+ * @param array $options
182+ * @return Route
183+ */
184+ protected function addResourceBatchDestroy (string $ name , string $ base , string $ controller , array $ options ): Route
185+ {
186+ $ uri = $ this ->getNestedResourceUriWithoutNestedParameter ($ name , $ base ).'/batch ' ;
187+
188+ $ action = $ this ->getResourceAction ($ name , $ controller , 'batchDestroy ' , $ options );
189+
190+ return $ this ->router ->delete ($ uri , $ action );
191+ }
192+
193+ /**
194+ * Add the batch restore for a resourceful route.
195+ *
196+ * @param string $name
197+ * @param string $base
198+ * @param string $controller
199+ * @param array $options
200+ * @return Route
201+ */
202+ protected function addResourceBatchRestore (string $ name , string $ base , string $ controller , array $ options ): Route
203+ {
204+ $ uri = $ this ->getNestedResourceUriWithoutNestedParameter ($ name , $ base ).'/batch/restore ' ;
205+
206+ $ action = $ this ->getResourceAction ($ name , $ controller , 'batchRestore ' , $ options );
207+
208+ return $ this ->router ->post ($ uri , $ action );
209+ }
210+
211+ protected function getNestedResourceUriWithNestedParameter (string $ name , string $ base ): string
212+ {
213+ $ uri = $ this ->getNestedResourceUriWithoutNestedParameter ($ name , $ base );
214+ $ uri .= "/{ " .$ base ."?} " ;
215+
216+ return $ uri ;
217+ }
218+
219+ protected function getNestedResourceUriWithoutNestedParameter (string $ name , string $ base ): string
220+ {
221+ $ uri = $ this ->getNestedResourceUri (explode ('. ' , $ name ));
222+
223+ return rtrim (rtrim ($ uri , "\{ $ base\} " ), '/ ' );
224+ }
225+ }
0 commit comments