🚗🏍️ Welcome to Motoshare!

Turning Idle Vehicles into Shared Rides & New Earnings.
Why let your bike or car sit idle when it can earn for you and move someone else forward?

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Partners earn. Renters ride. Everyone wins.

Start Your Journey with Motoshare

Example of Laravel Blade forEach Last Element

Laravel

Some of the most significant examples of a Laravel foreach loop last will be provided in this article. Here is a basic illustration of a Laravel foreach loop last. Every last element of the Lavel Blade will be taught to you. The following example will assist you in crafting each final item. Now let’s get started with the steps.

A @foreach loop is provided by Laravel Blade to render array data. To ascertain if an element is the initial or final one and apply a class or other actions correspondingly, you can make use of $loop->first and $loop->last.I’ll walk you through some basic examples of how to use $loop->first and $loop->last in your blade file.

Example 1 in blade page

@foreach ($users as $user)
    @if ($loop->first)
        This is the first item.
    @endif
  
    @if ($loop->last)
        This is the last item.
    @endif
  
    <p>This is user {{ $user->name }}</p>
@endforeach

Example 2:

<ul>
@foreach ($users as $user)
  <li @if ($loop->first) class="active" @endif>
    {{ $user->name }}
  </li>
@endforeach
</ul>

Example 3:

<ul>
@foreach ($users as $user)
  <li @if ($loop->last) class="active" @endif>
    {{ $user->name }}
  </li>
@endforeach
</ul>
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x