File tree 3 files changed +52
-0
lines changed
3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php namespace Conner \Tagging \Events ;
2
+
3
+ use Illuminate \Queue \SerializesModels ;
4
+ use Illuminate \Database \Eloquent \Model ;
5
+
6
+ class TagAdded extends Event
7
+ {
8
+ use SerializesModels;
9
+
10
+ /** @var \Illuminate\Database\Eloquent\Model **/
11
+ public $ model ;
12
+
13
+ /**
14
+ * Create a new event instance.
15
+ *
16
+ * @param Model $model
17
+ * @return void
18
+ */
19
+ public function __construct (Model $ model )
20
+ {
21
+ $ this ->model = $ model ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ <?php namespace Conner \Tagging \Events ;
2
+
3
+ use Illuminate \Queue \SerializesModels ;
4
+ use Illuminate \Database \Eloquent \Model ;
5
+
6
+ class TagRemoved extends Event
7
+ {
8
+ use SerializesModels;
9
+
10
+ /** @var \Illuminate\Database\Eloquent\Model **/
11
+ public $ model ;
12
+
13
+ /**
14
+ * Create a new event instance.
15
+ *
16
+ * @param Model $model
17
+ * @return void
18
+ */
19
+ public function __construct (Model $ model )
20
+ {
21
+ $ this ->model = $ model ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change 4
4
use Illuminate \Database \Eloquent \Collection ;
5
5
use Conner \Tagging \Model \Tagged ;
6
6
use Conner \Tagging \Contracts \TaggingUtility ;
7
+ use Conner \Tagging \Events \TagRemoved ;
8
+ use Conner \Tagging \Events \TagAdded ;
7
9
8
10
/**
9
11
* Copyright (C) 2014 Robert Conner
@@ -236,6 +238,8 @@ private function addTag($tagName)
236
238
$ this ->tagged ()->save ($ tagged );
237
239
238
240
static ::$ taggingUtility ->incrementCount ($ tagName , $ tagSlug , 1 );
241
+
242
+ event (new TagAdded ($ this ));
239
243
}
240
244
241
245
/**
@@ -255,6 +259,8 @@ private function removeTag($tagName)
255
259
if ($ count = $ this ->tagged ()->where ('tag_slug ' , '= ' , $ tagSlug )->delete ()) {
256
260
static ::$ taggingUtility ->decrementCount ($ tagName , $ tagSlug , $ count );
257
261
}
262
+
263
+ event (new TagRemoved ($ this ));
258
264
}
259
265
260
266
/**
You can’t perform that action at this time.
0 commit comments