Devolve um registro com base no campo e valor especificados.
Se $failable for true, falhas vão disparar ModelNotFoundException.

@param  mixed  $field
@param  mixed  $value
@param  bool $failable

@return Model
358172
public function findBy($field, $value = false, bool $failable = true)
    {
        $query = $this->newQuery();

        if(is_array($field)) {
            $failable = $value === true ? true : false;
            foreach ($field as $k => $v) {
                $query->where($k, $v);
            }
        } else {
            $query->where($field, $value);
        }

        if ($failable == true) {
            return $query->firstOrFail();
        }

        return $query->first();
    }
838307
public function map(callable $f) {
        if( $this->value !== null ) return Result::success($f($this->value));
        if( $this->error !== null ) return $this;
        throw new \LogicException("Value and error cannot both be null");
    }
885715
function setField($field, $value, $repetition = 0)
    {
        return $this->_impl->setField($field, $value, $repetition);
    }
1080614
public function data($field, $value = null)
    {
        if (is_null($value)) {
            return in_array($field, $this->getFillable()) ? $this->$field : $this->meta[$field];
        }

        if (in_array($field, $this->getFillable())) {
            $this->$field = $value;

            return $this->save();
        }

        return $this->setMeta($field, $value);
    }
1117469
public function gte($field, $value)
    {
        if(!$value instanceof Expr\ConditionalExpression) {
            $value = $this->buildPart($value);
        }
        return new Expr\ComparisonExpression($field, $value, Expr\ComparisonExpression::GTE);
    }
1077992
public function typecastLoadField(Field $f, $value)
    {
        try {
            // use $f->typecast = [typecast_save_callback, typecast_load_callback]
            if (is_array($f->typecast) && isset($f->typecast[1]) && is_callable($t = $f->typecast[1])) {
                return $t($value, $f, $this);
            }

            // only string type fields can use empty string as legit value, for all
            // other field types empty value is the same as no-value, nothing or null
            if ($f->type && $f->type != 'string' && $value === '') {
                return;
            }

            // we respect null values
            if ($value === null) {
                return;
            }

            // run persistence-specific typecasting of field value
            return $this->_typecastLoadField($f, $value);
        } catch (\Exception $e) {
            throw new Exception(['Unable to typecast field value on load', 'field' => $f->name], null, $e);
        }
    }
1366140
public function where($field, $value, $not = false)
    {
        $reserverd_word = $this->with_where ? 'AND' : 'WHERE';
        $operator = $not ? '!=' : '=';
        $this->query .= "{$reserverd_word} {$field} {$operator} '{$value}'";
        $this->with_where = true;

        return $this;
    }
674760
public static function mustBeNullableBoolean($value)
    {
        if (is_bool($value) === false && $value != null) {
            throw new MWrongTypeException('\$value', 'boolean|null', gettype($value));
        }
    }
896655
public function serializeSaveField(Field $f, $value)
    {
        try {
            // use $f->serialize = [encode_callback, decode_callback]
            if (is_array($f->serialize) && isset($f->serialize[0]) && is_callable($t = $f->serialize[0])) {
                return $t($f, $value, $this);
            }

            // run persistence-specific serialization of field value
            return $this->_serializeSaveField($f, $value);
        } catch (\Exception $e) {
            throw new Exception(['Unable to serialize field value on save', 'field' => $f->name], null, $e);
        }
    }
334809
public function hydrate($value)
    {
        if ($this->nullable && $value === null) {
            return null;
        }
        
        if ($value instanceof MongoBinData) {
            return $value->bin;
        }
        
        throw new Exception\InvalidArgumentException(sprintf(
            'Invalid value: must be an instance of MongoBinData, "%s" given',
            is_object($value) ? get_class($value) : gettype($value)
        ));
    }
545263
static function ByValue($value)
    {
        $calledClass = get_called_class();
        $allowed = self::AllowedClassValues($calledClass);
        if (!in_array($value, $allowed, true))
            throw new \InvalidArgumentException('Value ' . $value . ' not allowed for enum ' . $calledClass);
        
        return new $calledClass($value);
    }
499679
public function tryLoadBy($field, $value)
    {
        // store
        $field = $this->getField($field);
        $system = $field->system;
        $default = $field->default;

        // add condition and try to load record
        $this->addCondition($field, $value);

        try {
            $this->tryLoadAny();
        } catch (\Exception $e) {
            // restore
            array_pop($this->conditions);
            $field->system = $system;
            $field->default = $default;

            throw $e;
        }

        // restore
        array_pop($this->conditions);
        $field->system = $system;
        $field->default = $default;

        return $this;
    }
514301
public function set(string $field, $value)
    {
        $this->update();
        $this->mongoDbUpdate['$set'][$field] = $value;

        return $this;
    }
631101
public function setValue($value, $persist = true)
    {
        if ($this->isEmpty($value) && ! $this->flags & Value::CAN_BE_EMPTY) {
            throw FailedToValidate::fromValue($value, $this);
        }

        if (! $this->isEmpty($value)) {
            $value = $this->validate($value);
        }

        if (null === $value) {
            throw FailedToValidate::fromValue($value, $this);
        }

        $this->value = $value;

        if (! $persist ) {
            return $this;
        }

        $repository  = IdentityMap::getInstance()->getRepository($this->key);
        $repository->save($this);

        return $this;
    }
345755
public function findByID($id, bool $failable = false)
    {
        $query = $this->newQuery();
        if($this->soft_deletes == true) {
            $query->withTrashed();
        }

        return ($failable == true)
            ? $query->findOrFail($id) : $query->find($id);
    }
1209659
public function validate($value)
    {
        $value = filter_var($value, FILTER_VALIDATE_EMAIL);
        if (false === $value) {
            throw FailedToValidate::fromValueForClass($value, static::class);
        }
        return $value;
    }
649015
public function lt($field, $value)
    {
        return function ($object) use ($field, $value) {
            return ClosureExpressionBuilder::getObjectFieldValue($object, $field) < $value;
        };
    }