Ad

Search In Subarray

- 1 answer

I have arrays which I get so

 $article_foundd = Article::all();

Array itself

"["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" 

I need that when a person entered “sport” in the search bar, then all articles related to sports would be displayed, for example. Search all by meta_keywords

At the moment I have implemented a meta title, but I need to use the keys.

$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);
Ad

Answer

Try this example query for searching items by field meta_keyword

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