zengyyh 3 weeks ago
parent 4993d2d560
commit e13797acc7
  1. 12
      app/api/controller/Course.php

@ -33,9 +33,17 @@ class Course extends Controller
if(empty($list)){ if(empty($list)){
return $this->renderError("没有课程"); return $this->renderError("没有课程");
} }
$image_ids = array_column(($list->toArray())['data'], 'image_id');
$video_ids = array_column(($list->toArray())['data'], 'video_id');
$images= array_unique(array_merge($image_ids,$video_ids));
$image = UploadFile::withoutGlobalScope()->whereIn('file_id',$images)->select();
$list_image = array_column($image->toArray(), null ,'file_id');
foreach($list as $value){ foreach($list as $value){
$value['image_url'] = UploadFile::withoutGlobalScope()->where('file_id', '=',$value['image_id'])->find(); $value['image_url'] = $list_image[$value['image_id']] ?? [];
$value['video_url'] = UploadFile::withoutGlobalScope()->where('file_id', '=',$value['video_id'])->find(); $value['video_url'] = $list_image[$value['video_id']] ?? [];
} }
return $this->renderSuccess(compact('list')); return $this->renderSuccess(compact('list'));

Loading…
Cancel
Save