簡體   English   中英

在 Laravel 中調用單個 id 中的兩個關系表。 (查看照片)

[英]Call two relational tables in a singe id in Laravel. (check photos)

我正在嘗試將以下響應合並到一個條目中

在這里,我有兩把鑰匙,但我將如何用一把鑰匙制作它。

在我的 controller 中,我為 author 和 authorprofile 的兩個不同資源指定了 id。 但是我如何使用單一資源,因為作者和作者簡介在關系表中。

在此處輸入圖像描述

請檢查截圖中的資源屬性。

嘿,最好使用 Eloquent 關系,就像如果你有Author Model 和AuthorProfile Model 所以你把下面的方法放在 Author Model

public function Authorprofile(){
return $this->belongsTo(AuthorProfile::class, 'authorprofile_id');
}

然后在 Controller 中使用。

public function show($id){
 $author = Author::with('Authorprofile')->find($id)
}

希望它可能會有所幫助

暫無
暫無

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

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