浏览代码

预加载音乐

durong 5 年之前
父节点
当前提交
be799bb4ac
共有 2 个文件被更改,包括 3 次插入2 次删除
  1. 2 2
      app/Models/PostMusicCategoryRel.php
  2. 1 0
      app/Repositories/MusicRepository.php

+ 2 - 2
app/Models/PostMusicCategoryRel.php

@@ -16,12 +16,12 @@ class PostMusicCategoryRel extends Model {
     protected $guarded = [];
 
     //音乐
-    public function postMusic()
+    public function post_music()
     {
         return $this->hasOne('App\Models\PostMusic', 'id', 'mid');
     }
     //音乐分类
-    public function postCategory()
+    public function post_music_category()
     {
         return $this->hasOne('App\Models\PostMusicCategory', 'id', 'music_category_id');
     }

+ 1 - 0
app/Repositories/MusicRepository.php

@@ -59,6 +59,7 @@ class MusicRepository
         $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
 
         $postMusicList = $this->postMusicCategoryRel
+            ->with('post_music')
             ->join('post_music_category', 'post_music_category.id', '=', 'post_music_category_rel.music_category_id')
             ->join('post_music', 'post_music.id', '=', 'post_music_category_rel.mid')
             ->select('post_music.*', 'post_music_category_rel.sort')