File tree Expand file tree Collapse file tree 3 files changed +44
-20
lines changed
Expand file tree Collapse file tree 3 files changed +44
-20
lines changed Original file line number Diff line number Diff line change @@ -25,25 +25,7 @@ public function index($model, $slug_label)
2525
2626 public function store (LabelRequest $ request )
2727 {
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- }
28+ resolve ('LabelService ' )->create ($ request );
4729
4830 return back ()->with ('success ' , trans ('gitscrum.label-added-successfully ' ));
4931 }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Laravel GitScrum <https://github.com/GitScrum-Community/laravel-gitscrum>
4+ *
5+ * The MIT License (MIT)
6+ * Copyright (c) 2017 Renato Marinho <renato.marinho@s2move.com>
7+ */
8+
9+ namespace GitScrum \Services ;
10+
11+ use Config ;
12+ use GitScrum \Http \Requests \LabelRequest ;
13+ use GitScrum \Models \Label ;
14+
15+ class LabelService extends Service
16+ {
17+ public function create (LabelRequest $ request )
18+ {
19+ $ data = [
20+ 'labelable_id ' => $ request ->labelable_id ,
21+ 'labelable_type ' => $ request ->labelable_type ,
22+ 'title ' => $ request ->title ,
23+ ];
24+
25+ try {
26+ $ label = Label::create ($ data );
27+ } catch (\Exception $ e ) {
28+ $ label = Label::where ('title ' , $ request ->title )->first ();
29+ }
30+
31+ $ relation = Config::get ('database.relation ' );
32+
33+ $ result = $ relation [$ request ->labelable_type ]::where ('id ' , $ request ->labelable_id )->first ();
34+
35+ if (!$ result ->labels ()->where ('label_id ' , $ label ->id )->first ()) {
36+ $ result ->labels ()->attach ([$ label ->id ]);
37+ }
38+
39+ return $ label ;
40+ }
41+ }
Original file line number Diff line number Diff line change 141141 'CommentService ' ,
142142 'ConfigStatusService ' ,
143143 'FavoriteService ' ,
144- 'IssueService '
144+ 'IssueService ' ,
145+ 'LabelService '
145146 ],
146147
147148 /*
You can’t perform that action at this time.
0 commit comments