Reputation: 100
I'm setting up a sidebar which has been included on every page of the web site and this sidebar contain a span tag which need to be updated on every reload of the page i created a session variable in the main Controller and this work just for the first time after the Auth
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\Valeur;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function __construct()
{
$this->middleware('auth');
session(['values' => Valeur::where('etat', 1)->count()]);
}
}
**The result now ** after login i get the expected result but if i made a change in the Database the value of the session variable wont changes
Upvotes: 0
Views: 846
Reputation: 3022
You should use View Composers that allows you to retrieve the data for your views, whenever they are going do be rendered.
Upvotes: 1