在 Laravel 中使用 Eloquent ORM 使用 LIKE 执行数据库搜索 [英] Using Eloquent ORM in Laravel to perform search of database using LIKE

查看:35
本文介绍了在 Laravel 中使用 Eloquent ORM 使用 LIKE 执行数据库搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Eloquent 的活动记录构建来构建搜索查询,但它将是一个 LIKE 搜索.我找到了 User::find($term)User::find(1),但这不会生成类似语句.我不是在寻找直接的答案,但如果有人至少可以给我一个查看的方向,那就太好了!

I want to use Eloquent's active record building to build a search query, but it is going to be a LIKE search. I have found the User::find($term) or User::find(1), but this is not generating a like statement. I'm not looking for a direct answer, but if someone could at least give me a direction to look in that'd be great!

推荐答案

您可以使用 LIKE 和以下语法进行数据库查找:

You're able to do database finds using LIKE with this syntax:

Model::where('column', 'LIKE', '%value%')->get();

这篇关于在 Laravel 中使用 Eloquent ORM 使用 LIKE 执行数据库搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆