-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTagController.php
More file actions
41 lines (35 loc) · 1.37 KB
/
TagController.php
File metadata and controls
41 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace App\Http\Controllers;
use App\Article;
use App\Cate;
use Illuminate\Http\Request;
use App\Tag;
class TagController extends Controller
{
//标签列表
public function list()
{
$query = Tag::groupby('id');
$tags = $query->get();
$total = Tag::all()->count();
$articleCount = Article::all()->count();
$catesCount = Cate::all()->count();
$tagsCount = Tag::all()->count();
return view(env('BLOG_THEME') . '.tags.list', compact('tags', 'total', 'articleCount', 'catesCount', 'tagsCount'));
}
//标签详情
public function show($tid)
{
$articles = Tag::findOrFail($tid)->articles()->where('is_hidden', 0)->orderBy('created_at', 'desc')->paginate(10);
for ($i = 0; $i < sizeof($articles); $i++) {
$articles[$i]->content = str_limit(strip_tags($articles[$i]->content), 150);
$articles[$i]->created_at_date = $articles[$i]->created_at->toDateString();
$articles[$i]->updated_at_diff = $articles[$i]->updated_at->diffForHumans();
}
$tagName = Tag::find($tid)->name;
$articleCount = Article::all()->count();
$catesCount = Cate::all()->count();
$tagsCount = Tag::all()->count();
return view(env('BLOG_THEME') . '.tags.show', compact('articles', 'tagName', 'articleCount', 'catesCount', 'tagsCount'));
}
}