当数据在数组中时如何在laravel中创建分页

时间:2017-09-20 16:11:57

标签: php arrays laravel pagination

我正在尝试在laravel中创建分页,但我写的任何方法都说在数组上调用成员函数

控制器功能

 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'));
}

查看

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

我知道我在数组中转换数据但是如何将其转换为对象以便我可以使用这些方法links() count() total()

1 个答案:

答案 0 :(得分:0)

试试这个

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'));
}