Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to foreach categories from 3rd index from my database / Laravel?

I am issuing a problem with the following:

I foreach-ed my categories from index 1 to 3 in my blade file.

Code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@foreach($categories->take(3) as $category)
<ul>
<li>{{$category->name}}</li>
</ul>
@endforeach

But now I want to foreach second half of my categories from my database on the other ul list.

How to do that..?

Thanks:)

>Solution :

You can use splice method
to popout the first 3 elements and then use another foreach to create another ul list from the other categories like below:

<?php

@foreach($categories->splice(0, 3) as $category)
<ul>
  <li><a>{{ $category->name }}</a>
</ul>
@endforeach

@foreach($categories as $category)
<ul>
  <li><a>{{ $category->name }}</a>
</ul>
@endforeach
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading