I would like to populate a list on a Blade page, in the Laravel Framework. I tried
<select id="idSelMinhaLista">
@if(isset($arrayRemessa))
@for($i=0;$i < count($arrayRemessa);$i++)
<option>{{$arrayRemessa[$i]}}</option>
@endfor
@endif
</select>
The variable $ arrayRemessa is fed by a call to a PHP method, which, in turn, makes a Return by calling the View Blade that shows the select above. The method does:
public function listarArquivosRemessa(){
$arrayRemessa = [];
$filesInFolder = \File::files('assets/remessa');
foreach($filesInFolder as $path)
{
$arrayRemessa[] = pathinfo($path);
}
return view ("PesquisaView")->with("arrayRemessa",$arrayRemessa);
}//listarArquivosRemessa
My problem is that I have the following error:
htmlspecialchars () expects parameter 1 to be string, array given
My 'cowardly' exit was to use jQuery. This is:
In the View, simply:
<select id="idSelItauArquivosRemessa">
</select>
<button type="button" id="idBtnRefreshListaRemessaItau">Refresh</button>
No jQuery:
jQuery("#idBtnRefreshListaRemessa").click(function (){
var objSel=jQuery("#idSelItauArquivosRemessa");
objSel.empty();
var concatena='<option value="0" title="0"></option>';
jQuery.get("itauRefreshArquivosRemessa",function(retorno){
for(i=0;i < retorno.length;i++){
concatena=concatena+'<option value="'+retorno[i].basename+' "title="'+retorno[i].basename+'">'+retorno[i].basename+'</option>';
}//for
objSel.append(concatena);
});//get
});//idBtnRefreshListaRemessa
Na Route: Route :: get ('itauRefreshArchivesRemessa', 'ExpensesController @ listArchivesRemessaItau');
In method:
public function listarArquivosRemessaItau(){
$arrayRemessa = array_map('pathinfo', \File::files('assets/remessa'));
return $arrayRemessa;
}//listarArquivosRemessaItau