Issue
I am issuing a problem with the following:
I foreach-ed my categories from index 1 to 3 in my blade file.
Code
@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
Answered By - nice_dev Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.