在User和Post模型中,我将简单的RelationShip创建为:
帖子模特:
Dim xmlBody3 As String = "<recipientViewRequest xmlns=""http://www.docusign.com/restapi"">" &
"<authenticationMethod>email</authenticationMethod>" &
"<editors><canEditRecipientEmails>false</canEditRecipientEmails><canEditRecipientNames>false</canEditRecipientNames></editors>" &
"<email>" & recipientEmail3 & "</email>" &
"<returnUrl>" & returnUrl2 & "</returnUrl>" &
"<clientUserId>100003</clientUserId>" &
"<userName>" & recipientName3 & "</userName>" &
"</recipientViewRequest>"
url = "https://demo.docusign.net/restapi/v2/login_information"
Dim myRequest3 As System.Net.HttpWebRequest = initializeRequest(url, "GET", Nothing, username, password, integratorKey)
Dim myResponse3 As String = getResponseBody(myRequest3)
baseURL = parseDataFromResponse(myResponse3, "baseUrl")
url = baseURL & "/envelopes/" & eid & "/views/recipient"
myRequest3 = initializeRequest(url, "POST", xmlBody3, username, password, integratorKey)
myResponse3 = getResponseBody(myRequest3)
Dim recipientView3 As String = parseDataFromResponse(myResponse3, "url")
用户模型:
public function user()
{
return $this->belongsTo('App\User');
}
在数据库中创建新项目我在帖子表中有public function posts()
{
return $this->hasMany('App\Posts');
}
,例如user_id
。将此代码用于控制器后:
1
我在posts表中没有user_id信息。例如,posts表中的user_id是$all_records = \App\Posts::all();
,我希望将子查询作为id为1的所有用户表
答案 0 :(得分:0)
问题解决了:
$all_records = \App\Posts::with('user')->get();
答案 1 :(得分:0)
如果您想要user_id为1的所有帖子,那么您可以说:
User::find(1)->posts
;