Jump to content

Split awards into classes


Imanol

Recommended Posts

  • 3 weeks later...
On 12/2/2023 at 4:16 AM, DisposableHero said:

I think this can be done in blade... If you know the codes of awards for hours/pirep counts, then you can alter the foreach loop to show only them at top section (or left section) then the rest at bottom etc. (according to your placing wishes)

 

 

 

Hi @DisposableHero! I modified the original code to show awards into a Bootstrap grid. I need two of this rows, one for hours/pireps awards and the other one for awards in general, but I don't know how to edit the foreach. Thanks.

 

{{-- Show the user's award if they have any --}}
                @if (Auth::user()->awards)
                <div class="row">
                  <div class="col-sm-12">
                    @foreach(Auth::user()->awards->chunk(3) as $awards)
                    <div class="row">
                      @foreach($awards as $award)
                      <div class="col-md-4">
                        <div class="header header-primary text-center">
                          @if ($award->image_url)
                          <div class="photo-container">
                            <img class="img-fluid" src="{{ $award->image_url }}" alt="{{ $award->description }}">
                          </div>
                          @endif
                        </div>
                      </div>
                      @endforeach
                    </div>
                    <div class="clearfix" style="height: 20px;"></div>
                    @endforeach

 

Link to comment
Share on other sites

@foreach($awards->whereIn('id', [1,2,3,4]) as $award)

 

You need to know the id numbers of the awards you wish to group for this to work. more info at https://laravel.com/docs/10.x/collections#method-wherein you can use other available methods too.

 

But there is a logical flaw in the code above, Auth always gives you the logged in user. So for example if you place this code to profile index page and then visit my profile, you will see your own awards ;) 

 

Hope this helps, good luck

Link to comment
Share on other sites

On 12/22/2023 at 12:56 PM, DisposableHero said:

@foreach($awards->whereIn('id', [1,2,3,4]) as $award)

 

You need to know the id numbers of the awards you wish to group for this to work. more info at https://laravel.com/docs/10.x/collections#method-wherein you can use other available methods too.

 

But there is a logical flaw in the code above, Auth always gives you the logged in user. So for example if you place this code to profile index page and then visit my profile, you will see your own awards ;) 

 

Hope this helps, good luck

 

I appreciate it. Happy Holidays!

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...