Save value of a variable in laravel

1

I'm starting a project in Laravel, and in the sidebar I have a dropdow with a list in which I access the database and I bring information from 3 companies for example, and when I click on one of these companies, I would like to save the value of the id so that I can use this value to insert into the database along with an insert or update in another register, how could I do this?

Controller Method:

public static function emitentes(){
    $users = User::where('id', 1)->with('emitentes')->get()->first();
    $emp_user = $users->emitentes;
    return $emp_user;
}

PHP block requesting information:

             @php

                use App\Http\Controllers\EmitenteController;
                use App\Models\Cliente;

                $empresas = EmitenteController::emitentes();

            @endphp

Dropdow code:

<li class="dropdown notifications-menu">

                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    <i class="fa fa-university"></i>
                    <span class="label label-warning">{{count($empresas)}}</span>
                </a>

                <ul class="dropdown-menu">

                    <li class="header">Você pode emitir recibo para {{count($empresas)}} empresas</li>

                    <li>

                        <ul class="menu">

                            @foreach($empresas as $e)
                                <li><!-- start notification -->
                                    <a href="#">
                                    <i class="fa fa-industry text-aqua"></i> {{$e->name}}
                                </a>
                            </li><!-- end notification -->
                            @endforeach

                        </ul>

                    </li>

                </ul>

            </li>

Sample image:

    
asked by anonymous 16.08.2017 / 05:11

1 answer

1

With PHP , an option would be to save id to cookies using setcookie . Example:

setcookie("empresa_id", '15');

To redeem the cookie value that is saved, just use $_COOKIE . See:

echo $_COOKIE["empresa_id"];

Laravel himself has some resources for the same purpose. See here in the documentation on Requests & Input .

Javavascript , you can also do with cookies , but if you prefer you can use localStorage . Here's an example:

// Atribui um valor a empresa_id em relação a empresa com valor 15
window.localStorage.setItem('empresa_id', '15');

// Resgata o empresa_id 
var usuario = window.localStorage.getItem('empresa_id');

// Remove o empresa_id 
window.localStorage.removeItem('empresa_id');
    
16.08.2017 / 05:34