Bilalfarhat24's avatar

Limiting Foreach in Blade

How we can limit the foreach in Laravel Blade?

@foreach($users as $key => $user)
     {{$user->option1}} <br>
@endforeach
0 likes
6 replies
SaeedPrez's avatar

Why don't you limit it in the controller before sending it to the view?

1 like
Bilalfarhat24's avatar

Because , In Option1 all values are same.. And i want to use it for caption of the list. E.g caption "Physics Dep" and below the list related to physics dep.

tykus's avatar

Like @SaeedPrez says, you should organise your data inside the controller; e.g. if it made sense for your application, you could filter a Collection returned by an Eloquent query and then groupBy('option1') key;

Having said that, it is probably a job for the query in the first instance; why don't you share the controller code and desired HTML to be generated?

1 like
mojtabanaemi's avatar

hello : I have to make a website for student hostel in that I have a spacial page for each hostel like Facebook account on that page every student or client can just see the spacial hostel post not all the hostels how can I do this, can I do this with limitation or no , if I can how I can

Please or to participate in this conversation.