tharinducs7
tharinducs7

Reputation: 109

How to optimize speed of data loading

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

Answers (3)

Farid M
Farid M

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

PHP Geek
PHP Geek

Reputation: 4033

use laravel pagination:it will show 15 records per page

$users =Items::where('active',1)->paginate(15);

Upvotes: 1

Vandolph Reyes
Vandolph Reyes

Reputation: 620

There would be 3 ways you could follow (IMO)

  1. Cache
  2. Use pagination
  3. Don't use Eloquent. Using just DB::select is much faster as Eloquent tends to use a lot of class or objects.

Upvotes: 2

Related Questions