私はlaravel..onceにダッシュボードコントローラを持っています。私はセッションのuserIdを保存しています..every機能私はセッション変数userIdにアクセスする必要があります。コンストラクタ変数にセッション値を格納する。laravelのコンストラクタセッションで保護された変数を使用する方法
protected $users;
protected $session;
protected $userId;
public function __construct(Users $users,Session $session){
$this->users = $users;
$this->session = $session;
if($this->session->has('userId)){
$this->userId = $this->session->get('userId);
}
}
public function login(){
// After success saving userId in session and assing like as below
$this->userId = $response['id'];
}
public function dashboard(){
echo $this->userId; // Is empty
}
これはどのような解決方法ですか?