Asked by: Muhabutti
I would like to know how to get very large number of rows in the controller, and dispay it to the view. my current code looks likes below.
this is the controller.
$users = \App\Models\User::select ('id','first_name','last_name','created_at')
->where('friend_id', '=', 0)
->orderBy('created_at')->get();
return view('layouts.users.friends', compact('users'));
this is the view.
@if (!empty($users))
@foreach($users as $user)
<tr>
<?php $count++ ?>
<td>
{!! $user->id !!}
</td>
<td>{!! $user->first_name .' ' .$user->last_name !!}</td>
<td> {!! $user->created_at->format("d-m-y") !!} </td>
</tr>
@endforeach
@endif
Now i have 40,000 rows in the table, and when try to get the view error code 500, outof memory. I have to get all the rows. Please advice me what should be done. here. I have heard about laravel 5 chunk. but dont know who to display it on the view. Please help.


No comments:
Post a Comment