海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
918 B

  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\UserChannel;
  5. use Illuminate\Http\Request;
  6. class UserChannelController extends Controller
  7. {
  8. //我的频道列表
  9. public function index()
  10. {
  11. $channels = UserChannel::where('user_id', $this->user_id)->value('channels');
  12. return $this->success($channels);
  13. }
  14. // 我的频道编辑
  15. public function update(Request $request)
  16. {
  17. $formData = $request->only(['channels']);
  18. $request->validate([
  19. 'channels' => 'required|array',
  20. ], [
  21. 'channels.required' => '未选择任何频道',
  22. 'channels.array' => 'channels必须是数组',
  23. ]);
  24. $channels = array_unique(array_filter($formData['channels']));
  25. $UserChannel = UserChannel::where('user_id', $this->user_id)->first();
  26. $UserChannel->channels = $channels;
  27. $UserChannel->save();
  28. return $this->success();
  29. }
  30. }