/
TagController.php
54 lines (41 loc) · 1.11 KB
/
TagController.php
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
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Snippet;
use App\Tag;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class TagController extends Controller
{
private $tag;
public function __construct(Tag $tag)
{
$this->tag = $tag;
$this->middleware('auth');
}
/**
* タグ一覧
* @return $this
*/
public function all()
{
$tags = $this->tag->paginate(30);
return view('tag.tags')->with(compact('tags'));
}
/**
* タグ検索一覧
* @param $tagName
* @return $this
*/
public function tag($tagName)
{
try {
$tag = $this->tag->where('tag', 'like', $tagName)->firstOrFail();
$snippetsWithTag = $this->tag->getSnippetWithTags($tag->id);
$tagCount = $this->tag->getSnippetWithTagsCount($tag->id);
return view('tag.tagSearch')->with(compact('tag', 'snippetsWithTag', 'tagCount'));
} catch(ModelNotFoundException $e) {
return \Response::view('errors.404', [], '404');
}
}
}