1
|
|
|
<?php namespace Modules\Blog\Http\Controllers\Admin; |
2
|
|
|
|
3
|
|
|
use Illuminate\Http\Request; |
4
|
|
|
use Laracasts\Flash\Flash; |
5
|
|
|
use Modules\Blog\Entities\Tag; |
6
|
|
|
use Modules\Blog\Repositories\TagRepository; |
7
|
|
|
use Modules\Core\Http\Controllers\Admin\AdminBaseController; |
8
|
|
|
|
9
|
|
|
class TagController extends AdminBaseController |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var TagRepository |
13
|
|
|
*/ |
14
|
|
|
private $tag; |
15
|
|
|
|
16
|
|
|
public function __construct(TagRepository $tag) |
17
|
|
|
{ |
18
|
|
|
parent::__construct(); |
19
|
|
|
|
20
|
|
|
$this->tag = $tag; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Display a listing of the resource. |
25
|
|
|
* |
26
|
|
|
* @return Response |
27
|
|
|
*/ |
28
|
|
|
public function index() |
29
|
|
|
{ |
30
|
|
|
$tags = $this->tag->all(); |
31
|
|
|
|
32
|
|
|
return view('blog::admin.tags.index', compact('tags')); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Show the form for creating a new resource. |
37
|
|
|
* |
38
|
|
|
* @return Response |
39
|
|
|
*/ |
40
|
|
|
public function create() |
41
|
|
|
{ |
42
|
|
|
return view('blog::admin.tags.create'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Store a newly created resource in storage. |
47
|
|
|
* |
48
|
|
|
* @param Request $request |
49
|
|
|
* @return Response |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function store(Request $request) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$this->tag->create($request->all()); |
54
|
|
|
|
55
|
|
|
flash()->success(trans('core::core.messages.resource created', ['name' => trans('blog::tag.title.tag')])); |
56
|
|
|
|
57
|
|
|
return redirect()->route('admin.blog.tag.index'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Show the form for editing the specified resource. |
62
|
|
|
* |
63
|
|
|
* @param Tag $tag |
64
|
|
|
* @return Response |
65
|
|
|
*/ |
66
|
|
|
public function edit(Tag $tag) |
67
|
|
|
{ |
68
|
|
|
return view('blog::admin.tags.edit', compact('tag')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Update the specified resource in storage. |
73
|
|
|
* |
74
|
|
|
* @param Tag $tag |
75
|
|
|
* @param Request $request |
76
|
|
|
* @return Response |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
public function update(Tag $tag, Request $request) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
$this->tag->update($tag, $request->all()); |
81
|
|
|
|
82
|
|
|
flash()->success(trans('core::core.messages.resource updated', ['name' => trans('blog::tag.title.tag')])); |
83
|
|
|
|
84
|
|
|
return redirect()->route('admin.blog.tag.index'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Remove the specified resource from storage. |
89
|
|
|
* |
90
|
|
|
* @param Tag $tag |
91
|
|
|
* @return Response |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function destroy(Tag $tag) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$this->tag->destroy($tag); |
96
|
|
|
|
97
|
|
|
flash()->success(trans('core::core.messages.resource deleted', ['name' => trans('blog::tag.title.tag')])); |
98
|
|
|
|
99
|
|
|
return redirect()->route('admin.blog.tag.index'); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.