This works fine but what I want to know is if there is a better way to do a search for tags in Laravel. Thanks.
Tag model:
class Tag extends Model
{
public function noticias()
{
return $this->morphedByMany('App\Models\Noticia', 'taggable');
}
// ...
}
Noticia model:
class Noticia extends Model
{
public function tags()
{
return $this->morphToMany('App\Models\Tag', 'taggable');
}
// ...
}
SearchController
public function tag($id){
$noticias= Noticia::all();
$data['noticias'] = [];
foreach($noticias as $value){
foreach($value->tags as $tag){
if($tag->id == $id){
$data['noticias'][] = $value;
}
}
}
return view('web.buscar.index');
}