skip to Main Content

i am trying to use chunk method in laravel to show my data in the blade but I get it empty

here is my code

$accounts = Acc_account::where('cat', 2)->chunk(200, function (account) {
            foreach ($accounts as $account) {
                //
            }
        }); ;

and here is my code in blade

@foreach ($accounts as $item)
@endforeach

2

Answers


  1. try this

    $accounts = [];
        Acc_account::where('cat', 2)->chunk(200, function ($chunkedAccounts) use (&$accounts) {
            foreach ($chunkedAccounts as $account) {
                $accounts[] = $account;
            }
        });
        return view('your.blade.view', compact('accounts'));
    
    Login or Signup to reply.
  2. You can also use paginate(), in case of listing records in blade file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search