本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::whereSlug方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::whereSlug方法的具体用法?PHP Builder::whereSlug怎么用?PHP Builder::whereSlug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::whereSlug方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scopeWhereSlug
/**
* 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);
});
}
示例2: scopeSlug
/**
* 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);
}
示例3: findFromQuery
/**
* @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);
}