VideoCategoryController.php 947 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace Modules\Video\Http\Controllers;
  3. use Catch\Base\CatchController;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\DB;
  6. class VideoCategoryController extends CatchController
  7. {
  8. /**
  9. * 视频分类
  10. * @param Request $request
  11. * @return array
  12. */
  13. public function list(Request $request) {
  14. $videoCategorys = DB::table('video_category')
  15. ->get();
  16. $pCategory = $videoCategorys->where('pid', '=', 0)->all();
  17. $data = [];
  18. foreach ($pCategory as $item) {
  19. $data[$item->id] = [
  20. 'value' => $item->id,
  21. 'label' => $item->category_name,
  22. ];
  23. }
  24. foreach ($videoCategorys->where('pid', '!=', 0)->all() as $item) {
  25. $data[$item->pid]['children'][] = [
  26. 'value' => $item->id, 'label' => $item->category_name,
  27. ];
  28. }
  29. return array_values($data);
  30. }
  31. }