|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* GitScrum v0.1. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Renato Marinho <[email protected]> |
|
6
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace GitScrum\Http\Controllers; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Http\Request; |
|
12
|
|
|
use GitScrum\Http\Requests\LabelRequest; |
|
13
|
|
|
use GitScrum\Models\Label; |
|
14
|
|
|
|
|
15
|
|
|
class LabelController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
public function index($model, $slug_label) |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
$label = Label::slug($slug_label)->first(); |
|
20
|
|
|
|
|
21
|
|
|
return view('labels.index') |
|
|
|
|
|
|
22
|
|
|
->with('label', $label) |
|
23
|
|
|
->with('list', $label->$model()->paginate(env('APP_PAGINATE'))); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function store(LabelRequest $request) |
|
27
|
|
|
{ |
|
28
|
|
|
$data = [ |
|
29
|
|
|
'labelable_id' => $request->labelable_id, |
|
|
|
|
|
|
30
|
|
|
'labelable_type' => $request->labelable_type, |
|
|
|
|
|
|
31
|
|
|
'title' => $request->title, |
|
|
|
|
|
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
try { |
|
35
|
|
|
$label = Label::create($data); |
|
36
|
|
|
} catch (\Exception $e) { |
|
37
|
|
|
$label = Label::where('title', $request->title)->first(); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$relation = \Config::get('database.relation'); |
|
41
|
|
|
|
|
42
|
|
|
$result = $relation[$request->labelable_type]::where('id', $request->labelable_id)->first(); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
if (!$result->labels()->where('label_id', $label->id)->first()) { |
|
45
|
|
|
$result->labels()->attach([$label->id]); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return back()->with('success', trans('Label added successfully')); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function update(Request $request, $id) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function destroy($id) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.