webdevask.com

Menu

  • Home
  • New
  • Add question

php - How can limited span class item list in Laravel

View Original

Limit to item list: Limit to item list

More Description from the Pics: More Description from the Pics

I want to limited max item list at Laravel, As you if select all filter in admin panel, its look like this. So how can limited first 5 item to popular filters ?

 <div class="g-attributes">
                <span class="attr-title" style="color: orange"><b><i class="icofont-medal"></i> {{$translate_attribute->name ?? ""}}:</b> </span>
                @foreach($termsByAttribute as $term )
                    @php $translate_term = $term->translateOrOrigin(app()->getLocale()) @endphp
                    <span class="item {{$term->slug}} term-{{$term->id}}" style="color: green" >{{$translate_term->name}}</span>
                @endforeach
            </div>

Answer

Solution:

You can use the Collection's take() method to grab the first 5 elements:

@foreach($termsByAttribute->take(5) as $term)

Answer

Solution:

Your question isnt very clear, but I am assuming that you want to be able retrieve the last 5 rows of the table, in your controller, you can get the records like this

$termsByAttribute = Table::latest()->take(5)->get();

Source

See also:

  • php สร้าง Google ชีตจากบัญชีบริการ

  • php - Laravel 8.0 Installation Failed

  • javascript - How to include HTML data (tags) as value in "arrayToDataTable" of Google Pie Chart?

  • how to Grouping array in php

  • php - vender folder from my laravel project has more 1k error

© 2021
E-mail: contact@webdevask.com
Back to top