Problems with laravel 5.3

3

I'm having trouble setting and grabbing items from a sessão , in this case I'm setting which page should I mark in the menu as active .

No __contruct of my controller I'm doing this:

public function __construct()
{
    $this->middleware('auth');
    session()->put('pagina', 'I');
}

And on my pages where the menu looks like this:

<li {{((Session('pagina') == 'H')? 'class="active"' : '')}}>
    <a href="/"><i class="zmdi zmdi-home"></i> Home</a>
</li>
<li {{((Session('pagina') == 'C')? 'class="active"' : '')}}>
    <a href="/igrejas"><i class="zmdi zmdi-assignment-account"></i> Igreja</a>
</li>
<li {{((Session('pagina') == 'I')? 'class="active"' : '')}}>
    <a href="/celulas"><i class="zmdi zmdi-accounts-alt"></i> {{ (($igreja->FLG_MODEL_IGREJ == 'C')? 'Celulas' : (($igreja->FLG_MODEL_IGREJ == 'P')? 'Pequenos Grupos' : 'Salas dominicais' )) }}</a>
</li>

But the menu is not coming marked, I gave a dd in the Session and it is returning null , what to do?

I also tried to add functions in my controller and I was not successful as in the example below:

public function index(){
    session()->put('pagina', 'I');


    if(Auth::user()->FLG_USUAR_MASTE == 1) {
        return view('aa');
    }else{
        return view('aa');
    }

}
    
asked by anonymous 06.01.2017 / 11:47

1 answer

1

This is specified and I do not see why this version (5.3) has done that, but the truth is that accessing the authenticated session / user in the constructor is no longer supported, not long ago either I was" desperate " for a solution but I did not get a workaround that worked, my advice is to follow documentation but in my case it did not work (later I noticed that it was because the version of my project was smaller than 5.3.4).

The advice I can give you in this case is that you make this operation session()->put('pagina', 'I'); in the method called by the route (or other) instead of the constructor.

Here and in the documentation I see that:

  

Before using this feature, make sure that your application is running Laravel 5.3.4 or above:

That is, you should be running version 5.3.4 or higher, otherwise this solution does not work, and you should even choose to use your session in another method other than the constructor. To see the version that your project is doing: php artisan --version

    
06.01.2017 / 11:54