Reputation: 109
I have a for-each in my views. let's say it does have 5000 data. so it take sometime to load the page. because those data are loaded to a data table in view. is there anyway to optimize and load them quickly??
In blade View
@foreach($items as $item)
<tr>
<td>{{$item->name}}</td>
...
...
...
</tr>
@endforeach
in controller
$items = Items::where('active',1)->get();
Upvotes: 0
Views: 536
Reputation: 63
if you have to use all result without pagination you could use :
$contents = View::make('view', compact('$items'))->render();
with this code, it will be buffering and showing the data after creating HTML code
Upvotes: 1
Reputation: 4033
use laravel pagination:it will show 15 records per page
$users =Items::where('active',1)->paginate(15);
Upvotes: 1
Reputation: 620
There would be 3 ways you could follow (IMO)
DB::select
is much faster as Eloquent tends to use a lot of class or objects.Upvotes: 2