Przeglądaj źródła

定义与 TagMap 模型的一对多关系

visuddhinanda 1 rok temu
rodzic
commit
513f82a6bf
1 zmienionych plików z 12 dodań i 2 usunięć
  1. 12 2
      api-v8/app/Models/Tag.php

+ 12 - 2
api-v8/app/Models/Tag.php

@@ -8,13 +8,23 @@ use Illuminate\Database\Eloquent\Model;
 class Tag extends Model
 {
 
+    protected $primaryKey = 'id';
     protected $keyType = 'string';
-	protected $fillable = ['name' , 'owner_id'];
+    protected $casts = [
+        'id' => 'string'
+    ];
+    protected $fillable = ['name', 'owner_id'];
 
     use HasFactory;
 
     public function chapters()
     {
-        return $this->belongsToMany('App\Models\ProgressChapter','tag_maps','tag_id','anchor_id');
+        return $this->belongsToMany('App\Models\ProgressChapter', 'tag_maps', 'tag_id', 'anchor_id');
+    }
+
+    // 定义与 TagMap 模型的一对多关系
+    public function tag_maps()
+    {
+        return $this->hasMany(TagMap::class);
     }
 }