I have a method at a Model like this:
public function questionOwner($id)
{
if (auth()->user()->id == $id) {
return true;
}else{
return false;
}
}
Now I wanted to refactor this function so I tried this:
public function queOwner($id)
{
return !! auth()->user()->id == $id;
}
So if auth()->user()->id
was not equals to $id
, then it should return false
because of !!
but I don’t know why it always return TRUE!
So if you know what’s going wrong here and how can I refactor this function, please let me know, thanks…
3
Answers
Maybe that’s what you mean?
you could do in two ways
or
A full example could be found here: https://php.band/D2pzfPA2t
So, to avoid such a situation, use Strict comparison (Identical) or (better) strict typing.