I need query of my model with method (where) and using LIKE to find results;
Its my code:
public function scopeTags($query, $tags)
{
/*
* random = [ 'tag1', 'tag2', 'tag3', ...]
*/
$random = $tags[rand(0, count($tags) - 1)];
return $query->where('tags', 'LIKE', "%{$random}%");
}
I need something like that:
public function scopeTags($query, $tags)
{
/*
* random = [ 'tag1', 'tag2', 'tag3', ...]
*/
foreach($tags as $tag) {
$random[] = "%{$tag}%";
}
return $query->where('tags', 'LIKE', $random);
}
What's the best way to do it?