Reputation: 247
I have this variable on class/Controller level $songRating
and i am calling this method through ajax, when i first time call this method it runs the if
block which is good. and now $songRating
should be 1
.
But this is not a case. When i call this method it again runs the if
block. Dont know why :/
public $songRating;
public function GetHighRatedSong()
{
if($this->songRating == null){
$this->songRating=1;
}else{
$this->songRating=2;
}
return response()->json($this->songRating);
}
Upvotes: 0
Views: 211
Reputation: 1
It's because everytime you call that function or make a new instantiation to the class, it will automatically reset to it's original value. Try to use service container
Upvotes: 0
Reputation: 38642
Try with Replacing
$this->songrating=1;
to
$this->songRating=1; # song+Rating != song+rating
Upvotes: 2