visuddhinanda 10 місяців тому
батько
коміт
e3f123b4b8
1 змінених файлів з 22 додано та 11 видалено
  1. 22 11
      api-v8/app/Models/ProgressChapter.php

+ 22 - 11
api-v8/app/Models/ProgressChapter.php

@@ -8,14 +8,23 @@ use Illuminate\Database\Eloquent\Model;
 class ProgressChapter extends Model
 {
     use HasFactory;
-	protected $fillable = ['book' , 'book', 'channel_id','lang'=>'en',
-                            'all_trans','public','progress',
-                            'title','created_at','updated_at'];
-      protected $casts = [
-            'uid' => 'string'
-        ];
+    protected $fillable = [
+        'book',
+        'book',
+        'channel_id',
+        'lang' => 'en',
+        'all_trans',
+        'public',
+        'progress',
+        'title',
+        'created_at',
+        'updated_at'
+    ];
+    protected $casts = [
+        'uid' => 'string'
+    ];
     protected $primaryKey = 'uid';
-    
+
     //protected $dateFormat = 'U';
 
     public function tagid()
@@ -25,14 +34,16 @@ class ProgressChapter extends Model
 
     public function tags()
     {
-        return $this->belongsToMany('App\Models\Tag','tag_maps','anchor_id','tag_id');
+        return $this->belongsToMany('App\Models\Tag', 'tag_maps', 'anchor_id', 'tag_id');
     }
-
+    /**
+     * 关联到 Channel 模型
+     * channel_id 关联到 channel 表的 uid 字段
+     */
     public function channel()
     {
-        return $this->hasOne('App\Models\Channel', 'uid', 'channel_id'); //参数一:需要关联的子表类名,前面必须加上命名空间  参数二:子表关联父表的字段  参数三:父表关联子表的字段
+        return $this->hasOne(Channel::class, 'uid', 'channel_id');
     }
-
     public function views()
     {
         return $this->hasMany('App\Models\View', 'target_id', 'uid');