-1

I am trying to create pagination in laravel but any method i write it say call to member function on array

controller function

 public function city(city $job_city)
    {

        $data = privatejobcity::where('city_id', $job_city->id)->orderBy('city_id', 'DESC')->get();

        $private_job = [];
        foreach ($data as $values) {

            $private_job[] = private_jobadb::with('cities')->where('id', $values->private_jobabd_id)->orderBy('id', 'DESC')->paginate(15);
        }


        return view('frontend.jobTestCatagory.jobsByCities', compact('data', 'private_job'));
}

View

 <h6>Showing<span>{{$private_job->firstItem()}}
                        - {{$private_job->count()}}</span>of {{$private_job->total()}}
                        jobs</h6>
                        {{ $private_job->links() }}

i know i converted data in an array but how can I convert it into an object so I can use these methods links() count() total()

Faraz
  • 113
  • 1
  • 9
  • try wrapping the array in collection – Ragas Sep 20 '17 at 16:33
  • how? can u give me demo – Faraz Sep 20 '17 at 16:36
  • Collection does not seem to work. But You can Manually Create A Paginator in laravel. Go to this docs page https://laravel.com/docs/5.5/pagination#manually-creating-a-paginator – Ragas Sep 20 '17 at 16:40
  • The answer you are looking for is in this question https://stackoverflow.com/questions/29240758/manually-creating-a-paginator-laravel-5 – Ragas Sep 20 '17 at 16:46

1 Answers1

0

try this

public function city(city $job_city)
{

    $data = privatejobcity::where('city_id', $job_city->id)->orderBy('city_id', 'DESC')->get();

    $private_job = [];
    foreach ($data as $values) {

        $private_job[] = private_jobadb::with('cities')->where('id', $values->private_jobabd_id)->orderBy('id', 'DESC')->paginate(15);
    }

    $private_job = collect($private_job);


    return view('frontend.jobTestCatagory.jobsByCities', compact('data', 'private_job'));
}
Nitish Kumar
  • 6,054
  • 21
  • 82
  • 148
  • now it says `links() count() total()` does not exist – Faraz Sep 20 '17 at 19:08
  • can you edit your question with your schema? what is private_job output you expect? before going further, what is the difference between privatejobcity and privat_jobadb, if these two models are related, we can create relation in each model and of course make coding simpler – Matius Nugroho Aryanto Sep 20 '17 at 19:30