Left join key constraint data already exist


April 2019


9 time


this question is about how do I implement a scope where in, the user will claim a reward on a specific level and once they claim their rewards, the reward field will no longer display the reward that they have claimed. So for example:

The user is on level 20, on his reward panel, there are 3 available rewards to be claimed, level 10, 15 and 20. So if the user claimed the level 10 reward, it will no longer display on the panel except for level 15 and 20 rewards.

Here is the code for the blade:

 @foreach(App\LevelRewards::getRewards()->get() as $rewards)
 @if(Auth::user()->level >= $rewards->level_required || Auth::user()->level == $rewards->level_required)
            <div class="col-lg-2 col-md-3 col-sm-6 col-xs-6" style="margin: 5px 0px;">
               <div class="hovereffect">
                    <a href="#" class="d-block mb-4 h-100">
                   <input type ="hidden" name="id" value="{{$rewards->id}}"/>
                   <img class="img-responsive" src="{{asset('rewards_img/'.$rewards->picture)}}" alt="">
                <div class="overlay">
                 <h2 style="font-size: 14px;">{{$rewards->details}}</h2>
                 @if($rewards->type == 'physical')
                 <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#claimPhysical" data-details="{{$rewards->details}}" data-id="{{$rewards->id}}" data-level="{{$rewards->level_required}}" data-physical="{{$rewards->item_name}}">
                <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#claimDigital" data-id="{{$rewards->id}}" data-level="{{$rewards->level_required}}" data-physical="{{$rewards->item_name}}">
    <div style="background: #2d2d2d; padding: 9px;">
         <span class="credits_top">Required Level: <span>{{$rewards->level_required}}</span></span>

And this is the code for the model ClaimReward model:

public function scopeClaimLevel2($query)
    return $query->join('level_rewards','level_rewards.id','=','claim_rewards.reward_id')->select('claim_rewards.*');

Any links and source of information regarding this question will be highly appreciated. Thank you.

0 answers