mysql - Eloquent 进行长查询

标签 mysql laravel class phpmyadmin eloquent

如何使用多个 where 语句和 orderby 2 类型进行 Eloquent 查询,并对其进行分页或限制?

PostIco::table('posts')
    ->where('listingType', '!=', 1)
    ->OrderBy('listingType', 'created_at')
    ->limit(25)
    ->paginate(10)

如何让它发挥作用?

最佳答案

PostIco 是一个 Eloquent 模型吗?如果是这样,则不要对其使用 table 方法。

PostIco::where('listingType', '!=', 1)
    // Instead of OrderBy
    ->orderBy('listingType', 'asc')
    ->orderBy('created_at', 'desc')
    ->limit(25)
    ->paginate(10);

您还可以使用DB外观来做到这一点:

DB::table('posts')
    ->where('listingType', '!=', 1)
    ->orderBy('listingType', 'asc')
    ->orderBy('created_at', 'desc')
    ->limit(25)
    ->paginate(10);

编辑:更正 orderBy 语句

关于mysql - Eloquent 进行长查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49831047/

相关文章:

php - 将json中的数据从php插入到mysql表中

php - 更改模型名称 Laravel

php - Laravel 的 array_sort 助手 DESC e ASC

class - 可以在 C# 中的函数内部使用类吗

PHP/MySQL - 根据开始日期+ INSERT 确定一系列日期

MySQL count, group by 和 join 查询

php - laravel 5.1 以多对多关系获取每个类别的 5 个新闻

c++ - 如何通过参数内部的引用传递对象?

c++ - 无法编译。头文件。封闭自己的对象定义

mysql更新列自连接基于两个引用列(一种vlookup)