爲什麼firstOrFail()
會導致此雄辯查詢的結果發生變化?爲什麼firstOrFail更改此查詢的結果?
>>> Organization::find('300048');
=> Models\Organization {#889
id: 300048,
token: "redacted",
name: "DAYJK4EGPE",
domain: null,
created_at: "2017-05-19 17:42:55",
updated_at: "2017-05-19 17:42:56",
stripe_customer_id: "redacted",
referral_snippet: null,
primary_business: null,
}
>>> Organization::find('300048')->firstOrFail();
=> Models\Organization {#897
id: 300033,
token: "redacted",
name: "123456",
domain: "google.com",
created_at: "2017-05-17 13:24:23",
updated_at: "2017-05-24 15:50:25",
stripe_customer_id: "redacted",
referral_snippet: null,
primary_business: null,
}
>>>
的模型ID 300033
是我的數據庫中第一個,但我希望它仍然與ID 300048
回到該組織,因爲這是集合firstOrFail()
中唯一的結果就是被稱爲上。
我可以把它改成'where('id','300048') - > firstOrFail()'但這看起來很愚蠢。我想用'find()'。 – Henry
'哦,我需要使用'findOrFail()'... – Henry
請發表這個作爲你自己的問題的答案,因爲它可能會幫助別人。 – milo526