From 9740df6a977f004c04271b32b60d2e48ddd40b21 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Tue, 30 Jun 2020 10:46:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B7=AF=E7=94=B1=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/generate/factory/Route.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extend/catcher/generate/factory/Route.php b/extend/catcher/generate/factory/Route.php index dfd2f62..960a712 100644 --- a/extend/catcher/generate/factory/Route.php +++ b/extend/catcher/generate/factory/Route.php @@ -20,22 +20,24 @@ class Route extends Factory $route = []; if ($this->restful) { - $route[] = sprintf("\$router->resource('%s', '\%s')", $this->controllerName, $this->controller); + $route[] = sprintf("\$router->resource('%s', '\%s')->middleware('auth')", $this->controllerName, $this->controller); } if (!empty($this->methods)) { foreach ($this->methods as $method) { - $route[] = sprintf("\$router->%s('%s/%s', '\%s@%s')", $method[1], $this->controllerName, $method[0], $this->controller, $method[0] ); + $route[] = sprintf("\$router->%s('%s/%s', '\%s@%s')->middleware('auth')", $method[1], $this->controllerName, $method[0], $this->controller, $method[0] ); } } $router = $this->getModulePath($this->controller) . DIRECTORY_SEPARATOR . 'route.php'; + $comment = PHP_EOL . '//' . $this->controllerName . '路由' . PHP_EOL; + if (file_exists($router)) { - return file_put_contents($router, PHP_EOL . implode(';'. PHP_EOL , $route) . ';', FILE_APPEND); + return file_put_contents($router, PHP_EOL . $comment . implode(';'. PHP_EOL , $route) . ';', FILE_APPEND); } - return file_put_contents($router, $this->header() . implode(';'. PHP_EOL , $route) . ';'); + return file_put_contents($router, $this->header() . $comment. implode(';'. PHP_EOL , $route) . ';'); } /**