@@ -114,6 +114,13 @@ class Route
114114 */
115115 protected $ conditionalRequest = true ;
116116
117+ /**
118+ * Middleware applied to route.
119+ *
120+ * @var array
121+ */
122+ protected $ middleware ;
123+
117124 /**
118125 * Create a new route instance.
119126 *
@@ -238,15 +245,41 @@ public function getController()
238245 {
239246 if (! isset ($ this ->action ['uses ' ]) || ! is_string ($ this ->action ['uses ' ])) {
240247 return ;
248+ } elseif (isset ($ this ->controller )) {
249+ return $ this ->controller ;
241250 }
242251
243252 if (str_contains ($ this ->action ['uses ' ], '@ ' )) {
244253 list ($ controller , $ this ->method ) = explode ('@ ' , $ this ->action ['uses ' ]);
245254
246- $ this ->controller = $ this ->container ->make ($ controller );
255+ return $ this ->controller = $ this ->container ->make ($ controller );
256+ }
257+ }
258+
259+ /**
260+ * Get the middleware applied to the route.
261+ *
262+ * @return array
263+ */
264+ public function getMiddleware ()
265+ {
266+ if (! is_null ($ this ->middleware )) {
267+ return $ this ->middleware ;
268+ }
269+
270+ $ this ->middleware = [];
271+
272+ foreach ($ this ->action ['middleware ' ] as $ middleware ) {
273+ list ($ middleware , $ options ) = array_merge (explode (': ' , $ middleware ), [[]]);
274+
275+ $ this ->middleware [$ middleware ] = $ options ;
276+ }
277+
278+ if ($ controller = $ this ->getController ()) {
279+ $ this ->middleware = array_merge ($ this ->middleware , $ controller ->getMiddleware ());
247280 }
248281
249- return $ this ->controller ;
282+ return $ this ->middleware ;
250283 }
251284
252285 /**
0 commit comments