i am trying to store some data on load base controller of Laravel and I used constructor
to do this and constructor executes successfully. But when i am storing value in session and then refresh the page next time that same session value showing null:
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\Language;
use Session;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
function __construct()
{
if(Session::get('phrase') == null)
{
Session::put('phrase','test');
dump(Session::get('phrase'));
}
}
}
Accessing through:
class DashboardController extends Controller
{
public function index()
{
if(!in_array(Auth::user()->role_id,[1,2])){
return redirect()->route('orsers.list',['filters'=>'']);
}
return view('dashboard.index');
}
i can't understand where i am wrong??