Q:

Laravel 5.4: Avoid html in the Controllers and DB queries in the blade

I have a problem I can not solve. I have a foreach that prints me an HTML every time it finds value in the database, and it all works.
However, I would like to avoid putting html in the controller.php file.
At the moment I did:
$html_console='';
if($article->id_game > '0'){
  $prel_console = \DB::table('info_game')
      ->where('id_game', '=', $article->id_game)
      ->get();
  foreach($prel_console as $name_console)
  {
    $name_console_game = \DB::table('console')
        ->where('id', '=', $name_console->id_console)
        ->first();

    $html_console.='<span class="label">'. $name_console_game->abb_cat.'</span>' ;
  }
}

While in the blade:
{!! $html_console !!}

I tried to do this in the blade:
@foreach ($prel_console as $name_console)
  <span class="label margin-top-5 font-size-10">{{ $name_console_game->abb_cat }}</span>
@endforeach

If I put the foreach in the blade, how do I deal with the query "name_console_game"

A:

If you have a one to many relation between info_game table which should have a InfoGame model and console table with Console model then your could do something like this:
controller:
public function someMethod() 
{
    // assuming that you already have an $article object

    $infoGame = InfoGame::where('id_game', $article->id_game)->get();

    return view('some.view', compact('infoGame'));
}

view location views/some/view/blade.php
@foreach($infoGame->console as $name_console_game)

    <span>{{ $name_console_game->abb_cat }}</span>

@endforeach

