From f837c38c880633bd77474eb6f932fec6b0adabec Mon Sep 17 00:00:00 2001 From: liapples Date: Thu, 29 Jul 2021 19:11:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A2=91=E9=81=93=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=92=8C=E9=A2=91=E9=81=93=E7=BC=96=E8=BE=91=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/UserChannelController.php | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Api/UserChannelController.php b/app/Http/Controllers/Api/UserChannelController.php index 0c29275..75d07c0 100644 --- a/app/Http/Controllers/Api/UserChannelController.php +++ b/app/Http/Controllers/Api/UserChannelController.php @@ -3,18 +3,29 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; use App\Models\UserChannel; +use Illuminate\Http\Request; class UserChannelController extends Controller { + //我的频道列表 + public function index() + { + $channels = UserChannel::where('user_id', $this->user_id)->value('channels'); + return $this->success($channels); + } + // 我的频道编辑 - public function update() + public function update(Request $request) { - $channels = request()->input('channels'); - $channels = json_decode($channels, true); - if (!$channels) { - return $this->error('未选择任何频道'); - } - $channels = array_unique(array_filter($channels)); + $formData = $request->only(['channels']); + $request->validate([ + 'channels' => 'required|array', + ], [ + 'channels.required' => '未选择任何频道', + 'channels.array' => 'channels必须是数组', + ]); + + $channels = array_unique(array_filter($formData['channels'])); $UserChannel = UserChannel::where('user_id', $this->user_id)->first(); $UserChannel->channels = $channels;