本文整理匯總了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);
}