簡體   English   中英

如何使用變形一對多文件處理外鍵

[英]how to handle foreign key with morph one to many files

我有這些表:

file:
id - path - meme_type


fileable:
id - file_id - fileable_id - fileable_type


ticket_bodies:
id - title

TickeBody的每一行都有多個文件。 現在如何實現變形功能? (我不想將file表與可歸檔表結合起來)

像這樣的東西?

App\Models\File

public function fileable(){
    return $this->morphTo();
}

App\Models\TicketBody

public function files(){
    return $this->morphMany(App\Models\File::class, 'fileable');
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM