当前位置: 首页>>代码示例>>PHP>>正文


PHP Tag::whereSlug方法代码示例

本文整理汇总了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'));
 }
开发者ID:hongpyo,项目名称:l5essential,代码行数:15,代码来源:ArticlesController.php

示例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];
 }
开发者ID:wmk223,项目名称:site,代码行数:17,代码来源:TrickRepository.php

示例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);
 }
开发者ID:linuxssm,项目名称:l5essential,代码行数:16,代码来源:ArticlesController.php

示例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);
 }
开发者ID:misterebs,项目名称:cmsku,代码行数:55,代码来源:ArticleRepository.php

示例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'));
 }
开发者ID:ambarsetyawan,项目名称:laravel5-blog-1,代码行数:17,代码来源:TagsController.php

示例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();
     });
 }
开发者ID:realnerdo,项目名称:blog,代码行数:21,代码来源:RouteServiceProvider.php

示例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'));
 }
开发者ID:litemax,项目名称:LaravelBlog,代码行数:6,代码来源:TagController.php

示例8: show

 public function show($slug)
 {
     $tag = Tag::whereSlug($slug)->firstOrFail();
     $articles = $tag->articles()->latest()->simplePaginate(10);
     return view('articles.tag', compact('tag', 'articles'));
 }
开发者ID:misterebs,项目名称:cmsku,代码行数:6,代码来源:TagController.php

示例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);
     }
 }
开发者ID:ambarsetyawan,项目名称:brewski,代码行数:18,代码来源:Post.php


注:本文中的app\Tag::whereSlug方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。