From b42ad27f6fc49cad0624b4e3ed79a9ec40964a1f Mon Sep 17 00:00:00 2001 From: printempw Date: Mon, 7 Nov 2016 22:16:27 +0800 Subject: [PATCH] add events of player operations --- app/Events/PlayerWasAdded.php | 13 ------------- app/Events/PlayerWasDeleted.php | 19 +++++++++++++++++++ app/Events/PlayerWillBeAdded.php | 2 -- app/Events/PlayerWillBeDeleted.php | 21 +++++++++++++++++++++ app/Http/Controllers/PlayerController.php | 5 ++++- 5 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 app/Events/PlayerWasDeleted.php create mode 100644 app/Events/PlayerWillBeDeleted.php diff --git a/app/Events/PlayerWasAdded.php b/app/Events/PlayerWasAdded.php index 090c5c64..b0985ce1 100644 --- a/app/Events/PlayerWasAdded.php +++ b/app/Events/PlayerWasAdded.php @@ -3,13 +3,9 @@ namespace App\Events; use App\Models\Player; -use Illuminate\Queue\SerializesModels; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class PlayerWasAdded extends Event { - use SerializesModels; - public $player; /** @@ -22,13 +18,4 @@ class PlayerWasAdded extends Event $this->player = $player; } - /** - * Get the channels the event should be broadcast on. - * - * @return array - */ - public function broadcastOn() - { - return []; - } } diff --git a/app/Events/PlayerWasDeleted.php b/app/Events/PlayerWasDeleted.php new file mode 100644 index 00000000..698c9cf0 --- /dev/null +++ b/app/Events/PlayerWasDeleted.php @@ -0,0 +1,19 @@ +playerName = $player_name; + } + +} diff --git a/app/Events/PlayerWillBeAdded.php b/app/Events/PlayerWillBeAdded.php index 947f936b..8ede93e3 100644 --- a/app/Events/PlayerWillBeAdded.php +++ b/app/Events/PlayerWillBeAdded.php @@ -2,8 +2,6 @@ namespace App\Events; -use App\Models\Player; - class PlayerWillBeAdded extends Event { public $playerName; diff --git a/app/Events/PlayerWillBeDeleted.php b/app/Events/PlayerWillBeDeleted.php new file mode 100644 index 00000000..810cae84 --- /dev/null +++ b/app/Events/PlayerWillBeDeleted.php @@ -0,0 +1,21 @@ +player = $player; + } + +} diff --git a/app/Http/Controllers/PlayerController.php b/app/Http/Controllers/PlayerController.php index 15144f76..cdda2c8d 100644 --- a/app/Http/Controllers/PlayerController.php +++ b/app/Http/Controllers/PlayerController.php @@ -14,6 +14,7 @@ use App\Events\PlayerWasAdded; use App\Events\PlayerWasDeleted; use App\Events\CheckPlayerExists; use App\Events\PlayerWillBeAdded; +use App\Events\PlayerWillBeDeleted; use App\Exceptions\PrettyPageException; use App\Services\Repositories\UserRepository; @@ -83,10 +84,12 @@ class PlayerController extends Controller { $player_name = $this->player->player_name; + Event::fire(new PlayerWillBeDeleted($this->player)); + if ($this->player->delete()) { $this->user->setScore(Option::get('score_per_player'), 'plus'); - // Event::fire(new PlayerWasDeleted($this)); + Event::fire(new PlayerWasDeleted($player_name)); return json(trans('user.player.delete.success', ['name' => $player_name]), 0); }