-
Notifications
You must be signed in to change notification settings - Fork 299
/
TagsController.php
108 lines (89 loc) · 2.34 KB
/
TagsController.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Controllers\Admin;
use Controllers\BaseController;
use Tricks\Repositories\TagRepositoryInterface;
class TagsController extends BaseController
{
/**
* Tag repository.
*
* @var \Tricks\Repositories\TagRepositoryInterface
*/
protected $tags;
/**
* Create a new TagsController instance.
*
* @param \Tricks\Repositories\TagRepositoryInterface $tags
* @return void
*/
public function __construct(TagRepositoryInterface $tags)
{
parent::__construct();
$this->tags = $tags;
}
/**
* Show the tags index page.
*
* @return \Response
*/
public function getIndex()
{
$tags = $this->tags->findAll();
$this->view('admin.tags.list', compact('tags'));
}
/**
* Delete a tag from the database.
*
* @param mixed $id
* @return \Illuminate\Http\RedirectResponse
*/
public function getDelete($id)
{
$this->tags->delete($id);
return $this->redirectRoute('admin.tags.index');
}
/**
* Show the tag edit form.
*
* @param mixed $id
* @return \Response
*/
public function getView($id)
{
$tag = $this->tags->findById($id);
$this->view('admin.tags.edit', compact('tag'));
}
/**
* Handle the creation of a tag.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postIndex()
{
$form = $this->tags->getForm();
if (! $form->isValid()) {
return $this->redirectRoute('admin.tags.index')
->withErrors($form->getErrors())
->withInput();
}
$tag = $this->tags->create($form->getInputData());
return $this->redirectRoute('admin.tags.index');
}
/**
* Handle the editing of a tag.
*
* @param mixed $id
* @return \Illuminate\Http\RedirectResponse
*/
public function postView($id)
{
$form = $this->tags->getForm();
if (! $form->isValid()) {
return $this->redirectRoute('admin.tags.view', $id)
->withErrors($form->getErrors())
->withInput();
}
$tag = $this->tags->update($id, $form->getInputData());
return $this->redirectRoute('admin.tags.view', $id);
}
}