I have four models User
,Reward
,RewardUnlocked
,RewardClaimed
And the relationship between them is :
User
have many RewardUnlocked
,=>(Many to one)
User
have many RewardClaimed
=>(Many to one)
Reward
have many RewardUnlocked
=>(Many to one)
Reward
have many RewardClaimed
=>(Many to one)
The introduction of the problem is that a user will first unlock a reward when a specific condition becomes true,
Now the issue is that i want to fetch all the rewards from Reward
table and show to the user, And check each reward that if the reward_id
is present in RewardUnlocked
then show a check sign
if not present then show cross sign
The view file is a header
file so i am sending the variable via ajax.
For the time being my code is
controller :
$rewards = App\Reward::all();
foreach ($rewards as $reward){
$list = App\User::with('unlocks')->where('user_id','=', Auth::user()->id)->first();
}
The problem with the following code is that i have to send the reward list , And show there with a check sign or cross sign that you have unlocked the reward.