我有四個型號User
,Reward
,RewardUnlocked
,RewardClaimed
以及它們之間的關係是:Laravel:獲取記錄與條件
User
有很多RewardUnlocked
,=>(多對一)
User
有很多RewardClaimed
=>(多對一)
Reward
有許多RewardUnlocked
=>(多對一)
Reward
有很多RewardClaimed
=>(多對一)
引進的問題是,用戶將首先解鎖獎勵當特定條件爲真,
現在的問題是,我想從Reward
表獲取所有的獎勵,並顯示給用戶,並檢查各獎勵,如果reward_id
存在於RewardUnlocked
再展check sign
如果不存在,則表明cross sign
視圖文件是一個header
文件,所以我通過ajax發送變量。
就目前我的代碼是
控制器:
$rewards = App\Reward::all();
foreach ($rewards as $reward){
$list = App\User::with('unlocks')->where('user_id','=', Auth::user()->id)->first();
}
用下面的代碼的問題是,我要送獎勵名單,並配有檢查標誌或交叉顯示有表示您已解鎖獎勵。