mpgn
mpgn

Reputation: 7251

Laravel 4 paginate and orderBy

Normaly I call my database like this :

$data = array(
    'one' => MyORM::paginate($this->per_page),

);
return View::make('project.index')->with($data);

But I also want to use an OrderBy so I can use:

$data = array(
    'test' => MyORM::orderBy('date', 'DESC')->get(),
);
return View::make('project.index')->with($data);

But I don't know how I can "merge" the two codes?

I can also use :

$data = array(
    'test2' => DB::table('martialp')
        ->orderBy('date', 'DESC') 
        ->paginate(4)
);

But my class MyORM for exemple is useless with this previous code.

Upvotes: 1

Views: 2551

Answers (1)

Mitch
Mitch

Reputation: 1394

$data = MyORM::orderBy('date', 'DESC')->paginate(15);

return View::make('project.index', compact('data'));

Upvotes: 2

Related Questions