/**
  * Scopes query for slug on translated attribute
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param string                                $slug
  * @param string                                $locale
  * @return $this|null
  */
 public function scopeWhereSlug($query, $slug, $locale = null)
 {
     return $query->whereHas('translations', function ($query) use($slug, $locale) {
         return $query->whereSlug($slug, $locale, true);
     });
 }
Ejemplo n.º 2
0
 /**
  * Finds a tag by its slug.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  string  $slug
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeSlug(Builder $query, $slug)
 {
     return $query->whereSlug($slug);
 }
Ejemplo n.º 3
0
 /**
  * @param Builder                  $query
  * @param int|string|AbstractModel $item
  *
  * @return AbstractModel
  */
 protected function findFromQuery($query, $item)
 {
     $columns = ['*'];
     // If we have an instance already, return it
     if ($item instanceof Model) {
         return $item;
     }
     if ($this->items instanceof BelongsToMany) {
         $columns = [$this->items->getRelated()->getTable() . '.*'];
     }
     // Find by slug
     if (!is_array($item)) {
         if (!preg_match('/^[0-9]+$/', (string) $item) && $this->getModelInstance()->hasTrait('Cviebrock\\EloquentSluggable\\SluggableTrait')) {
             return $query->whereSlug($item)->firstOrFail();
         }
     }
     return $query->findOrFail($item, $columns);
 }