我想过滤一堆以字符开头后跟通配符 * 的名称
查询
我可以通过查询来实现这一点,例如:第一个月
由于我缓存了模态::类,所以我不想重复它,而是使用filter()或其他可以帮助我获得预期结果的东西。
集合过滤器()
return $collection->filter(function ($q) use ($name) {
return false !== stripos($q['name'], $name); // this returns all the names that contains $name character
});
字符串
我想实现的是filter()名称以特定字符开头,然后是'%' --$name . '%'
例如。'A%'
个
下面是我经历的几个SO链接
Collection Where LIKE Laravel 5.4
Laravel 5.5 Collection where like的
2条答案
按热度按时间yks3o0rb1#
你可以使用
Str::startsWith
助手。字符串
应用到您的代码,它应该是
型
对于laravel 5.7之前的版本,请使用
starts_with
助手。型
yhqotfr82#
考虑这个集合:
字符串
下面是一个
Collection
过滤记录的例子,它的工作原理与where like
sql query statement特性完全相同。型
用法
型
示例