public function check($code)
    {
        $promocode = Promocode::byCode($code)->first();

        if ($promocode === null) {
            throw new InvalidPromocodeException;
        }

        if ($promocode->isExpired() || ($promocode->isDisposable() && $promocode->users()->exists())) {
            return false;
        }

        return $promocode;
    }
public function check($code)
    {
        $promocode = Promocode::byCode($code)->first();

        if ($promocode === null) {
            throw new InvalidPromocodeException;
        }

        if ($promocode->isExpired() || ($promocode->isDisposable() && $promocode->users()->exists())) {
            return false;
        }

        return $promocode;
    }
public function check ( $ code ) { $ promocode = Promocode :: byCode ( $ code ) -> first ( ) ; if ( $ promocode === null ) { throw new InvalidPromocodeException ; } if ( $ promocode -> isExpired ( ) || ( $ promocode -> isDisposable ( ) && $ promocode -> users ( ) -> exists ( ) ) ) { return false ; } return $ promocode ; }
Check promocode in database if it is valid.

@param string $code

@return bool|Promocode
@throws InvalidPromocodeException
Check promocode in database if it is valid .