本文整理汇总了PHP中app\Tag::whereSlug方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::whereSlug方法的具体用法?PHP Tag::whereSlug怎么用?PHP Tag::whereSlug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Tag
的用法示例。
在下文中一共展示了Tag::whereSlug方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @param \App\Http\Requests\FilterArticlesRequest $request
* @param string|null $slug
* @return \Illuminate\Http\Response
*/
public function index(FilterArticlesRequest $request, $slug = null)
{
$query = $slug ? Tag::whereSlug($slug)->firstOrFail()->articles() : new Article();
// If you are relying on 'file' or 'database' cache, cacheTags() methods is not available
$query = taggable() ? $query->with('comments', 'author', 'tags', 'solution', 'attachments')->remember(5)->cacheTags('articles') : $query->with('comments', 'author', 'tags', 'solution', 'attachments')->remember(5);
$articles = $this->filter($request, $query)->paginate(10);
return view('articles.index', compact('articles'));
}
示例2: findByTag
/**
* Find all tricks for the tag that matches the given slug.
*
* @param string $slug
* @param int $perPage
*
* @return \Illuminate\Pagination\LengthAwarePaginator|\App\Trick[]
*/
public function findByTag($slug, $perPage = self::PAGE_SIZE)
{
$tag = $this->tag->whereSlug($slug)->first();
if (is_null($tag)) {
throw new TagNotFoundException('The tag "' . $slug . '" does not exist!');
}
$tricks = $tag->tricks()->orderBy('created_at', 'desc')->paginate($perPage);
return [$tag, $tricks];
}
示例3: index
/**
* Display a listing of the resource.
*
* @param \App\Http\Requests\FilterArticlesRequest $request
* @param string|null $slug
* @return \Illuminate\Http\Response
*/
public function index(FilterArticlesRequest $request, $slug = null)
{
$query = $slug ? Tag::whereSlug($slug)->firstOrFail()->articles() : new Article();
$cacheKey = cache_key('articles.index');
$query = $this->filter($query->orderBy('pin', 'desc'));
$args = $request->input(config('project.params.limit'), 5);
$articles = $this->cache($cacheKey, 5, $query, 'paginate', $args);
return $this->respondCollection($articles, $cacheKey);
}
示例4: syncTags
public function syncTags(Article $article, $tags = array(), $isNew = false)
{
$tagall = Tag::all()->toArray();
$newTagIds = $updateTagIds = $existingSlug = $existingTag = [];
if (!empty($tagall)) {
foreach ($tagall as $tag) {
$existingSlug[] = $tag['slug'];
$existingTag[$tag['slug']] = $tag;
}
}
unset($tagall);
if ($tags) {
foreach ($tags as $tag) {
if (!in_array(mb_strtolower($tag, 'UTF-8'), $existingSlug)) {
$name = filter_allowed_words($tag);
$slug = preg_replace('/\\s+/', '-', mb_strtolower($name, 'UTF-8'));
if (in_array($slug, $existingSlug)) {
if ($isNew) {
Tag::whereSlug($slug)->increment('count');
}
$updateTagIds[] = $existingTag[$slug]['id'];
} else {
$firstLetter = getFirstLetter($name);
$newtag = Tag::create(array('name' => $name, 'slug' => $slug, 'letter' => $firstLetter));
$newId = $newtag->id;
$newTagIds[] = $newId;
$updateTagIds[] = $newId;
}
} else {
if ($isNew) {
Tag::whereSlug($tag)->increment('count');
}
$updateTagIds[] = $existingTag[$tag]['id'];
}
}
}
$updateTagIds = array_unique($updateTagIds);
if (!$isNew) {
$oldTagIds = $article->tags->lists('id')->toArray();
$delTagIds = array_diff($oldTagIds, $updateTagIds);
$addTagIds = array_diff($updateTagIds, $oldTagIds);
if (!empty($delTagIds)) {
Tag::whereIn('id', $delTagIds)->decrement('count');
}
if (!empty($addTagIds)) {
foreach ($addTagIds as $addId) {
if (!in_array($addId, $newTagIds)) {
Tag::whereId($addId)->increment('count');
}
}
}
}
$article->tags()->sync($updateTagIds);
unset($newTagIds, $updateTagIds, $existingSlug, $existingTag);
}
示例5: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($slug)
{
$page_size = env('num_per_page');
// $articles = Tag::findBySlug($slug)->articles()->latest()->paginate($page_size);
$articles = \App\Article::with('tags', 'category')->published()->whereHas('tags', function ($query) use($slug) {
$query->whereSlug($slug);
})->latest()->paginate($page_size);
$Tag = Tag::whereSlug($slug)->firstOrFail();
$Tagname = $Tag->name;
return view('blog.tags.show', compact('articles', 'Tagname'));
}
示例6: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
//
parent::boot($router);
// $router->model('articles', 'App\Article');
$router->bind('articles', function ($slug) {
return \App\Article::published()->whereSlug($slug)->firstOrFail();
});
$router->bind('tags', function ($slug) {
return \App\Tag::whereSlug($slug)->firstOrFail();
});
$router->bind('users', function ($slug) {
return \App\User::whereSlug($slug)->firstOrFail();
});
}
示例7: show
public function show($slug)
{
$tag = Tag::whereSlug($slug)->firstOrFail();
$articles = $tag->articles()->orderBy('created_at', 'desc')->simplePaginate(10);
return view('articles.tag', compact('tag', 'articles'));
}
示例8: show
public function show($slug)
{
$tag = Tag::whereSlug($slug)->firstOrFail();
$articles = $tag->articles()->latest()->simplePaginate(10);
return view('articles.tag', compact('tag', 'articles'));
}
示例9: setTags
public static function setTags($post, $tags = null)
{
$post->tags()->detach();
$post_tags = [];
if (isset($tags) && !empty($tags)) {
foreach ($tags as $key => $value) {
$current_tag = Tag::whereSlug(str_slug($value))->first();
if (!$current_tag) {
$new_tag = Tag::create(['name' => $value, 'slug' => str_slug($value)]);
$add_tag_id = $new_tag->id;
} else {
$add_tag_id = $current_tag->id;
}
array_push($post_tags, $add_tag_id);
}
$post->tags()->attach($post_tags);
}
}