Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nyel-dev's avatar

Can I put if else statements inside methods of models?

just looking for best practice for this stuff

class User extends Authenticatable
{
    public function isAdmin() {
    if($this->privilege === 1) {
            return true;
        }
  
        return false;
   }

    public function isOwner() {
    if($this->privilege === 2) {
            return true;
        }
  
        return false;
    }

    public function isCustomer() {
        if($this->privilege === 3) {
        return true;
        }
  
       return false;
    }
}

something like this

0 likes
1 reply
vajid's avatar

yes u can do it. You can clean up the code

public function isAdmin() {
    return $this->privilege === 1;
   }
2 likes

Please or to participate in this conversation.