|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Acme\Transformers\TagTransformer; |
|
6
|
|
|
use App\Tag; |
|
7
|
|
|
use App\Task; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
use Illuminate\Http\Response as IlluminateResponse; |
|
10
|
|
|
use Illuminate\Support\Facades\Input; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class TagController |
|
14
|
|
|
* @package App\Http\Controllers |
|
15
|
|
|
*/ |
|
16
|
|
|
class TagController extends ApiController |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var TagTransformer |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $tagTransformer; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* TagController constructor. |
|
25
|
|
|
* @param $tagTransformer |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(TagTransformer $tagTransformer) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->tagTransformer = $tagTransformer; |
|
30
|
|
|
$this->middleware('auth:api'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Display a listing of the resource. |
|
35
|
|
|
* @param null $taskId |
|
36
|
|
|
* @return \Illuminate\Http\Response |
|
37
|
|
|
*/ |
|
38
|
|
|
public function index($taskId = null) |
|
39
|
|
|
{ |
|
40
|
|
|
|
|
41
|
|
|
$tag = $this->getTags($taskId); |
|
42
|
|
|
return $this->respond($this->tagTransformer->transformCollection($tag->all())); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Show the form for creating a new resource. |
|
47
|
|
|
* |
|
48
|
|
|
* @return \Illuminate\Http\Response |
|
49
|
|
|
*/ |
|
50
|
|
|
public function create() |
|
51
|
|
|
{ |
|
52
|
|
|
// |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Store a newly created resource in storage. |
|
57
|
|
|
* @return \Illuminate\Http\Response |
|
58
|
|
|
*/ |
|
59
|
|
|
public function store() |
|
60
|
|
|
{ |
|
61
|
|
|
if (!Input::get('title')) { |
|
62
|
|
|
return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY) |
|
63
|
|
|
->respondWithError('Parameters failed validation for a task.'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
Tag::create(Input::all()); |
|
67
|
|
|
|
|
68
|
|
|
return $this->respondCreated('Task successfully created.'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Display the specified resource. |
|
73
|
|
|
* |
|
74
|
|
|
* @param int $id |
|
75
|
|
|
* @return \Illuminate\Http\Response |
|
76
|
|
|
*/ |
|
77
|
|
|
public function show($id) |
|
78
|
|
|
{ |
|
79
|
|
|
$tag = Tag::find($id); |
|
80
|
|
|
|
|
81
|
|
|
if (!$tag) { |
|
82
|
|
|
return $this->respondNotFound('Tag does not exsist'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $this->respond([ |
|
86
|
|
|
'data' => $this->tagTransformer->transform($tag) |
|
87
|
|
|
]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Show the form for editing the specified resource. |
|
92
|
|
|
* |
|
93
|
|
|
* @param int $id |
|
94
|
|
|
* @return \Illuminate\Http\Response |
|
95
|
|
|
*/ |
|
96
|
|
|
public function edit($id) |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
// |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Update the specified resource in storage. |
|
103
|
|
|
* |
|
104
|
|
|
* @param \Illuminate\Http\Request $request |
|
105
|
|
|
* @param int $id |
|
106
|
|
|
* @return \Illuminate\Http\Response |
|
107
|
|
|
*/ |
|
108
|
|
|
public function update(Request $request, $id) |
|
109
|
|
|
{ |
|
110
|
|
|
$tag = Tag::find($id); |
|
111
|
|
|
if (!$tag) { |
|
112
|
|
|
return $this->respondNotFound('Tag does not exist!'); |
|
113
|
|
|
} |
|
114
|
|
|
$tag->title = $request->title; |
|
|
|
|
|
|
115
|
|
|
$tag->save(); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Remove the specified resource from storage. |
|
120
|
|
|
* |
|
121
|
|
|
* @param int $id |
|
122
|
|
|
* @return \Illuminate\Http\Response |
|
123
|
|
|
*/ |
|
124
|
|
|
public function destroy($id) |
|
125
|
|
|
{ |
|
126
|
|
|
Tag::destroy($id); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param $taskId |
|
131
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|static[] |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getTags($taskId) |
|
134
|
|
|
{ |
|
135
|
|
|
return $taskId ? Task::findOrFail($taskId)->tags : Tag::all(); |
|
136
|
|
|
} |
|
137
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.