Laravel uses DB fuzzy query problem
PHPz
PHPz 2017-05-16 16:49:26
0
2
760

The document has an example: https://laravel.com/docs/5.3/...
As follows:

$users = DB::table('users')
                ->where('name', 'like', 'T%')
                ->get();

Question 1:
The above example only searches for one field name. If I have an articles table with two fields title and content that need fuzzy search, how should I write it?

$keywords= $request->input('keywords');
$articles = DB::table('articles')
                ->where('content', 'like', $keywords.'%') //这一句里面不止content,而是title和content两个字段
                ->get();

Question 2:
Are there any other settings or operations required to search for Chinese?

PHPz
PHPz

学习是最好的投资!

reply all(2)
为情所困
$keywords= $request->input('keywords');
$articles = DB::table('articles')
                ->where('content', 'like', $keywords.'%')
                ->orWhere('title', 'like', $keywords.'%')
                ->get();

Using Like to search Chinese does not require other settings or operations. It is not recommended to use like for this kind of full-text search operation. It is best to use search engines such as ElasticSearch or Sphinx to achieve it

小葫芦

You can try full text search

select * from articles where match (title,content) against ('keywords');
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template