小编Jes*_*sen的帖子

如何过滤掉以特定首字母开头的列表(laravel/eloquent)

我有一个字符串列表,只想获取以字母“B”开头的字符串。我尝试过以下代码但没有成功。

{{ $kentekens->where('kenteken', 'LIKE', 'B%') }}
Run Code Online (Sandbox Code Playgroud)

{{ $kentekens->filter(function ($value, $key) {
        return strpos($value, 'B') === 0;
    });
}}
Run Code Online (Sandbox Code Playgroud)

控制器

public function create() {
        $kentekens = Kenteken::latest()
            ->where('created_at', '>=', Carbon::today())
            ->get();

return view('layouts.dashboard', compact('kentekens'));
Run Code Online (Sandbox Code Playgroud)

有人知道正确的语法吗?

php laravel eloquent php-carbon

1
推荐指数
1
解决办法
4441
查看次数

标签 统计

eloquent ×1

laravel ×1

php ×1

php-carbon ×1