0
I’m using Laravel
as an example.
In the Controller
i do 2 searches.
public function index()
{
$page_title = "Relatório";
$projetos = Projetos::orderBy('alguma_coluna')->get();
$subprojetos = Subprojetos::get();
return view('pages.relatorio.index',
compact('page_title','projetos ','subprojetos ')
);
}
I need to do a treatment before printing this data on View
.
The code below is just an example of data processing
foreach($projetos AS $thisRow) {
$isDuplicate = false;
$projeto_nome = $thisRow["projeto_nome"];
$hasNewIcon = $thisRow["hasNewIcon"];
$img_src = $thisRow["img_src"];
if($hasNewIcon === "1"){
$hasNewIcon = "<img src='algumaimg.jpg'>";
} else {
$hasNewIcon = "";
}
foreach ($subprojetos AS $r) {
$subprojeto_nome = $r["subprojeto_nome"];
if($contador > 0){
$isDuplicate = true;
}
$contador++;
}
$html .= <<<HTML
<div class="col-lg-2 col-md-2 col-xs-6 thumb">
<img src="{$img_src}" class="img-responsive"/>
<div class="equal-height-panels">
<div class="row">
<h5 class="text-center">{$projeto_nome}</h5>
{$hasNewIcon}
</div>
</div>
</div>
HTML;
}
My question is: Where should I do this treatment? No Controller
, in View
or in the Model
?
It would be interesting for you to do any treatment at Model. And all these parts involving HTML you should put right into the View and do the conditionals there, using the Blade syntax.
– Laerte