mercredi 15 août 2018

Function to check if user is under a certain age returning true, when it should be returning false

I have a function that checks a users age based on the date of birth given. This is on my user model.

Date of birth is 1995-02-23

public function age()
    {
        return $this->date_of_birth->diffInYears(\Carbon\Carbon::now());
    }

When I run this in tinker against a certain user, I get the correct age. 23.

I also have a function to check which checks a users age, to determine which section of the site they can access.

public function Youth(){
  if($this->age() == 16 || 17){
    return true;
  } else {
    return false;
  }
}

This is returning true on the above user in tinker when it should be returning false, as the user's age is 23. Any obvious issues with my code?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire