Skip to content

Commit d14f45c

Browse files
committed
Add events
1 parent a6749e1 commit d14f45c

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/Events/TagAdded.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

src/Events/TagRemoved.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

src/Taggable.php

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use Illuminate\Database\Eloquent\Collection;
55
use Conner\Tagging\Model\Tagged;
66
use Conner\Tagging\Contracts\TaggingUtility;
7+
use Conner\Tagging\Events\TagRemoved;
8+
use Conner\Tagging\Events\TagAdded;
79

810
/**
911
* Copyright (C) 2014 Robert Conner
@@ -236,6 +238,8 @@ private function addTag($tagName)
236238
$this->tagged()->save($tagged);
237239

238240
static::$taggingUtility->incrementCount($tagName, $tagSlug, 1);
241+
242+
event(new TagAdded($this));
239243
}
240244

241245
/**
@@ -255,6 +259,8 @@ private function removeTag($tagName)
255259
if($count = $this->tagged()->where('tag_slug', '=', $tagSlug)->delete()) {
256260
static::$taggingUtility->decrementCount($tagName, $tagSlug, $count);
257261
}
262+
263+
event(new TagRemoved($this));
258264
}
259265

260266
/**

0 commit comments

Comments
 (0)