【问题标题】:Laravel 4 paginate and orderByLaravel 4 分页和排序
【发布时间】:2014-02-24 19:37:04
【问题描述】:

通常我这样称呼我的数据库:

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

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

但我也想使用 OrderBy 以便我可以使用:

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

但我不知道如何“合并”这两个代码?

我也可以使用:

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

但我的课程MyORM 对前面的代码毫无用处。

【问题讨论】:

    标签: php sql laravel-4


    【解决方案1】:
    $data = MyORM::orderBy('date', 'DESC')->paginate(15);
    
    return View::make('project.index', compact('data'));
    

    【讨论】:

    • 为什么 compact('data') 不是 ->whith($data)
    • compact() 函数创建一个包含变量及其值的数组。我一直只是根据个人喜好偏爱它。你可以在这里阅读更多:us2.php.net/manual/en/function.compact.php
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2013-02-19
    • 1970-01-01
    • 2014-12-10
    • 2019-11-24
    • 2014-11-02
    • 2015-08-17
    相关资源
    最近更新 更多