0

I added the following arrays into all_updates[] as follows :

$all_updates[] = $all_update_in;
$all_updates[] = $all_update_out;
$all_updates[] = $all_update_oth;

The $all_updates output :

array(3) { [0]=> array(0) { } [1]=> array(0) { } [2]=> array(3) { [0]=> object(stdClass)#365 (21) { ["id"]=> int(84) ["created_at"]=> string(19) "2019-10-31 12:24:28" ["updated_at"]=> string(19) "2019-10-31 12:24:28" ["title"]=> string(14) "the tag newest" ["body"]=> string(20) "the tag newest ANSWER" } } }

I'm trying to paginate the final array as follows :

$Final_array= $all_updates->paginate(15);

I'm receiving the following error :

Call to a member function paginate() on a non-object

2
  • 3
    the paginate() function is specific to query builder objects, you can't call it on arrays Commented Oct 31, 2019 at 15:42
  • If you post your full code, maybe we can give a better advice. Because, we need to know why you combine $all_update_in, $all_update_out, $all_update_oth after you separate them. Commented Oct 31, 2019 at 18:14

3 Answers 3

1

You can not paginate an array. You paginate the output of the query which is stored in an array but not the array itself.

That means that your 3 nested arrays should already be paginated before inserted in the parent array.

After that you loop around them and you get the links field. This is your pagination info.

Sign up to request clarification or add additional context in comments.

Comments

1

First you want to convert the array to collection using collect($arr)

Then check hakob93 answer on the following thread to move forward: https://laracasts.com/discuss/channels/laravel/how-to-paginate-laravel-collection?page=1#reply=363252

Comments

1

paginate() function is query builder that's why you can't use here .

but you can do with take() and slice().

like

$skipRow=0;

$data=[
  [
    'id'=>1,
    'name'=>'suresh'
  ]
  [
    'id'=>2,
    'name'=>'mahesh'
  ]
];

$collectedData=collect($data);

$rowData=$collectedData->slice($skipRow)->take(15);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.