add events of player operations

This commit is contained in:
printempw 2016-11-07 22:16:27 +08:00
parent ccbed31ab2
commit b42ad27f6f
5 changed files with 44 additions and 16 deletions

View File

@ -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 [];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Events;
class PlayerWasDeleted extends Event
{
public $playerName;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($player_name)
{
$this->playerName = $player_name;
}
}

View File

@ -2,8 +2,6 @@
namespace App\Events;
use App\Models\Player;
class PlayerWillBeAdded extends Event
{
public $playerName;

View File

@ -0,0 +1,21 @@
<?php
namespace App\Events;
use App\Models\Player;
class PlayerWillBeDeleted extends Event
{
public $player;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Player $player)
{
$this->player = $player;
}
}

View File

@ -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);
}