Laravel - Paginate and get()

Posted by Bajongskie on Stack Overflow See other posts from Stack Overflow or by Bajongskie
Published on 2013-10-27T09:50:09Z Indexed on 2013/10/27 9:53 UTC
Read the original article Hit count: 656

Filed under:
|
|
|

With the code below, what I wanted was paginate the query I created. But, when I try to add paginate after get, it throws an error. I wanted to remain get since I want to limit to columns that was set on $fields. What would should be the better idea to paginate this thing? or what's a good substitute for get and limit the columns?

What I tried:

->get($this->fields)->paginate($this->limit)

Part of my controller:

class PhonesController extends BaseController {

    protected $limit = 5;
    protected $fields = array('Phones.*','manufacturers.name as manufacturer');
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {



        if (Request::query("str")) {
            $phones = Phone::where("model", 'LIKE', '%'. Request::query('str') . '%')
                        ->join('manufacturers', 'manufacturers_id', '=', 'manufacturers.id')
                        ->get($this->fields);

        } else {
            $phones = Phone::join('manufacturers', 'manufacturers_id', '=', 'manufacturers.id')
                            ->get($this->fields);
        }



        return View::make('phones.index')->with('phones', $phones);
    }

}

© Stack Overflow or respective owner

Related posts about php

Related posts about pagination