From 86316342f28478fe05b7dc59f31f891eb2bf22fb Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Fri, 16 Sep 2022 21:36:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ForumController.php | 27 +++++++++--------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/ForumController.php b/app/Http/Controllers/ForumController.php index 03eec6d..d467a2c 100644 --- a/app/Http/Controllers/ForumController.php +++ b/app/Http/Controllers/ForumController.php @@ -22,31 +22,18 @@ public function __construct() public function get($url) { - - try { - $resp = $this->http->get($url)->json()['data']; - } catch (Exception $e) { - return $this->error($e); - } - - return $this->success($resp); + $resp = $this->http->get($url)->json()['data']; + return $resp; } public function announcements() { - $resp = $this->cache(function () { return $this->get('discussions?filter[tag]=announcements&page[offset]=0&sort=-commentCount'); }); - if (isset($resp->original['data'])) { - $resp = $resp->original['data']; - } else { - $resp = []; - } - - return $this->success($resp); + return $this->resp($resp); } @@ -55,9 +42,15 @@ public function cache(Closure $callback) // 获取调用方法名 $method = debug_backtrace()[1]['function']; - return Cache::remember('forum.func.' . $method . '.user_' . auth()->id(), 60, function () use ($callback) { return $callback(); }); } + + + public function resp($data) { + $data['base_url'] = $this->baseUrl; + + return $this->success($data); + } }