Show how you call the class as well. And this is on the parent class and you call a child class?
And I assume some other code sets the bearer_token in the session as this code does not?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i made a constructor function in my class and in which set that if anybody can call the function from class it will generate a token if it doesn't previously set in the session and it works on different classes but if i used it on function which is present is that constructor class the logic doesn't working and it generates token on every call
here's my code for constructor
public function __construct(){
$sessionName = '';
$loginObj = $this->crmLogin($this->ws_url,$this->username,$this->accesskey);
if($loginObj->sessionName){
$sessionName = $loginObj->sessionName;
session()->put('sessionName',$sessionName);
}
$data['accountholder_no'] = "AH00000059";
$postParams = array(
'operation' => 'GenerateToken',
'sessionName' => $sessionName,
'element' => json_encode($data)
);
$token_response = $this->postHttpRequest($this->ws_url, $postParams);
$token_response = json_decode($token_response);
if(Session()->has('bearer_token')){
return null;
}else{
$this->generateToken($data);
}
@laksh Then you need to debug this part (fixed the case of the helper as its session() not Session())
dd(session()->all());
if(session()->has('bearer_token')){
Please or to participate in this conversation.