2
I have, in PHP
, a method whose code returns values, passing them to a View
, as block below:
return view('PesquisaView')
->with('clientes',$resultadoClientes)
->with('advs',$resultadoAdvs)
->with('bps',$resultadoBPs)
->with('mensagemDoUploadRemessa',$avisoUpload);
However, this View has several tabs (tabs) based on the Boostrap framework and the 'Return' displays the View in the first tab, the one that was defined as 'active' at the beginning of the page use.
I would like the 'Return' statement, which causes the View to open, to show directly the tab I want, not the 'default'. In the case of 'id' 'Idpanecitipesquisarremessa'.
The html code that defines the guides is
<ul class="nav nav-tabs">
<li><a href="#idQExpert" data-toggle="tab">QExpert</a></li>
<li>
<a href="#idPaneCitiPesquisarRemessa" data-toggle="tab">Citibank - Remessa</a>
</li>
<li>
<a href="#idPaneCitiPesquisar" data-toggle="tab">Citibank - Retorno</a>
</li>
</ul>
Updating:
Taking advantage of @Virgilio Novic’s valuable suggestion (as well as @wmengue and @massreuy’s), I changed my code to the following:
Method in PHP:
$tab = 2;
return view('PesquisaView')
->with('clientes',$resultadoClientes)
->with('advs',$resultadoAdvs)
->with('bps',$resultadoBPs)
->with('mensagemDoUploadRemessa',$avisoUpload);
->with('tab',$tab);
HTML markup:
<ul class="nav nav-tabs" id="myTab">
<li class="{{$tab==1?'active':''}}"><a href="#idQExpert" data-toggle="tab">QExpert</a></li>
<li class="{{$tab==2?'active':''}}"><a href="#idPaneCitiPesquisarRemessa" data-toggle="tab">Citibank - Remessa</a>
</li>
<li class="{{$tab==3?'active':''}}">
<a href="#idPaneCitiPesquisar" data-toggle="tab">Citibank - Retorno</a>
</li>
</ul>
After executing the method, it returns the value 2 for the $tab variable, the View Blade accepts the parameter and highlights the 'Citibank - Shipment' tab (the middle tab, in the image below, which has the white background), but note that the content, which is a 'form' html, does not appear.
However, if the tabs are clicked, for page exchange, be the first or the third and, back to the second, there yes the form is rendered, as new image below:
That is, the click event does not happen when becoming the 'active' class via code.
I confess that I don’t know how to do this. I imagine it’s something like ...->with('class','<li class="active">')..., but I don’t know how to take advantage of your idea.
– user4701
@Maurosimoes Your question is how to send this from Laravel to the view or how to treat the parameter sent to it to place the class?
– wmengue
I confess that I do not see how to pass 'with' and, in View-Blade, how to take advantage of what comes from PHP.
– user4701
@Maurosimoes in the Blade view you can access the variable that went by php like this: {{ $nameVariavelUsadaNoWith }} so you will recover what was passed from php to the view-Blade
– wmengue
I have to test isset($nameVariavelUsadaNoWith) before applying the class, no?
– user4701
@Maurosimoes You can use the Laravel isset/endisset directive to view more information on https://laravel.com/docs/5.4/blade#control-Structures
– wmengue