php - 如何在使用 Carbon 在 Laravel/Eloquent 中使用 'count' 时出现 'where'

标签 php mysql laravel eloquent php-carbon

我想计算使用以下代码获得的输出:

Blade View

{{ $kentekens->where('created_at', '>=', Carbon::today()) }}

这给出了字符串输出,但我想计算它获得的匹配数量。 我尝试了以下方法但没有成功:

{{ $kentekens->where('created_at', '>=', Carbon::today()->count()) }}

{{ $kentekens->count()->where('created_at', '>=', Carbon::today()) }}

Controller

public function create() {
    $kentekens = Kenteken::latest()
        ->get();

    return view('layouts.dashboard', compact('kentekens'));
}

型号

class Kenteken extends Model {
    protected $table = "kenteken";
}

有人有什么想法吗?

最佳答案

正确的语法是:

{{ $kentekens->where('created_at', '>=', Carbon::today())->count() }}

关于php - 如何在使用 Carbon 在 Laravel/Eloquent 中使用 'count' 时出现 'where',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48389940/

相关文章:

php - CakePHP 3 : Exception not Found

php - 从数据中提取 JSON 数组

mysql - 接口(interface)错误: 2013: Lost connection to MySQL server during query

MYSQL - 日期时间到秒

Laravel 4.2 检查 whereIn 子句中的数组是否为空

php - 如何使用 Idiorm 和 Paris 仅通过一个查询从关联表中检索信息?

php - 检查一个数组是否包含另一个数组的所有元素

php - 阻止 Composer 更新重新安装

mysql - 'connect by' 或 'WITH RECURSIVE' 是否可以在高度连接的大数据场景中使用?

php - Laravel:错误 [PDOException]:在 PostgreSQL 中找不到驱动程序