-2
I would like to popular a list on a Blade page in the Laravel Framework. I tried to do
<select id="idSelMinhaLista">
@if(isset($arrayRemessa))
@for($i=0;$i < count($arrayRemessa);$i++)
<option>{{$arrayRemessa[$i]}}</option>
@endfor
@endif
</select>
The $arrayRemessa variable 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 makes:
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 error below:
htmlspecialchars() expects Parameter 1 to be string, array Given
My 'coward' exit was to use jQuery. This is:
Na View, simply:
<select id="idSelItauArquivosRemessa">
</select>
<button type="button" id="idBtnRefreshListaRemessaItau">Refresh</button>
In the 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
On Route: Route::get('itauRefreshAquivosRemessa','Despesascontroller@listararvosremessaitau');
In the method:
public function listarArquivosRemessaItau(){
$arrayRemessa = array_map('pathinfo', \File::files('assets/remessa'));
return $arrayRemessa;
}//listarArquivosRemessaItau
Where did that class come from
File
?– Jéf Bueno
You can improve your code even more by simply doing
$arrayRemessa = array_map('pathinfo', \File::file('assets/remessa'))
. It is not necessary to do all these operations when using functions that simplify the work– Wallace Maxters
Besides, it would be better to use
foreach
instead offor
– Wallace Maxters
none of these approaches worked out for me, but I resolved via jQuery.
– user4701