Laravelforeach cyclically outputs the index of the current loop

Source: Internet
Author: User
{Code ...} after foreach is done, I want to enter the index of the current loop to determine whether it is a double number or a singular number. By adding different class names through the index, the layout of different styles also determines whether thumb is a thumbnail in the cyclic data, if the thumb field has a thumbnail, enter it, no...
@foreach($sorts as $sort)                
  • thumb !== '') $sort -> thumb @else /images/type/type_no.png @endif" alt=""/>

    {{ $sort -> name }}

    @endforeach
  • After foreach is done, I want to enter the index of the current loop and determine whether it is a double number or a singular number. Adding different class names through the index is a different style layout.

    In addition, it is determined that thumb is a thumbnail in the cyclic data. If the thumb field has a thumbnail, It is input, and if it does not exist, the default image is output,

    @if($sort -> thumb !== '') $sort -> thumb @else /images/type/type_no.png @endif

    Can this be determined.

    Can you give me some guidance on the above two questions?

    Reply content:
    @foreach($sorts as $sort)                
  • thumb !== '') $sort -> thumb @else /images/type/type_no.png @endif" alt=""/>

    {{ $sort -> name }}

    @endforeach
  • After foreach is done, I want to enter the index of the current loop and determine whether it is a double number or a singular number. Adding different class names through the index is a different style layout.

    In addition, it is determined that thumb is a thumbnail in the cyclic data. If the thumb field has a thumbnail, It is input, and if it does not exist, the default image is output,

    @if($sort -> thumb !== '') $sort -> thumb @else /images/type/type_no.png @endif

    Can this be determined.

    Can you give me some guidance on the above two questions?

    php@foreach($sorts as $key=>$sort)    @if ($key%2 == 0)                
  • thumb or /images/type/type_no.png}}" alt=""/>

    {{ $sort -> name }}

    @else
  • thumb or /images/type/type_no.png}}" alt=""/>

    {{ $sort -> name }}

    @endif @endforeach
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.