首页 > 解决方案 > 在子数组中搜索

问题描述

我有我得到的数组

 $article_foundd = Article::all();

数组本身

"["meta_title"]=> string(5) "sport" 
 ["meta_description"]=> string(4) "NEWS" 
 ["meta_keyword"]=> string(7) "sport, olimp" 


"["meta_title"]=> string(7) "climate" 
 ["meta_description"]=> string(14) "Climate change" 
 ["meta_keyword"]=> string(19) "climate,weather,rain" 


"["meta_title"]=> string(7) "box"
 ["meta_description"]=> string(19) "box" 
 ["meta_keyword"]=> string(7) "sport,box,roy,tyson" 

例如,我需要当一个人在搜索栏中输入“运动”时,将显示所有与运动相关的文章。全部搜索meta_keywords

目前我已经实现了一个元标题,但我需要使用键。

$q = Input::get ( 'q' );
$article_found = Article::where('meta_title','LIKE','%'.$q.'%')->get();
if(count($article_found) > 0)
    return view('blog.search')->withDetails($article_found)->with('details' =>$article_found);

标签: phplaravel

解决方案


试试这个示例查询,按字段搜索项目meta_keyword

$article_found = Article::where('meta_keyword','LIKE','%'.$q.'%')->get();

推荐阅读