海南旅游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.

35 lines
867 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' => 'nullable|array',
  20. ], [
  21. 'channels.array' => 'channels必须是数组',
  22. ]);
  23. $channels = array_unique(array_filter($formData['channels']));
  24. $UserChannel = UserChannel::where('user_id', $this->user_id)->first();
  25. $UserChannel->channels = $channels;
  26. $UserChannel->save();
  27. return $this->success();
  28. }
  29. }