Exemple #1
0
 /**
  * Find a model by given key. (This would return first matching object).
  *
  * @param string $key
  * @param mixed $value
  *
  * @return Model
  */
 public function findBy(string $key, $value)
 {
     $this->applyCriteria();
     if ($this->isSearching()) {
         return $this->scout->where($key, $value)->get()->load($this->with);
     }
     $result = $this->getQuery()->where($key, $value)->first();
     if (!$result instanceof Model) {
         throw new NotFoundResourceException('Not found.');
     }
     return $result;
 }