add events of player operations
This commit is contained in:
parent
ccbed31ab2
commit
b42ad27f6f
@ -3,13 +3,9 @@
|
|||||||
namespace App\Events;
|
namespace App\Events;
|
||||||
|
|
||||||
use App\Models\Player;
|
use App\Models\Player;
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
||||||
|
|
||||||
class PlayerWasAdded extends Event
|
class PlayerWasAdded extends Event
|
||||||
{
|
{
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
public $player;
|
public $player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,13 +18,4 @@ class PlayerWasAdded extends Event
|
|||||||
$this->player = $player;
|
$this->player = $player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the channels the event should be broadcast on.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function broadcastOn()
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
19
app/Events/PlayerWasDeleted.php
Normal file
19
app/Events/PlayerWasDeleted.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Events;
|
namespace App\Events;
|
||||||
|
|
||||||
use App\Models\Player;
|
|
||||||
|
|
||||||
class PlayerWillBeAdded extends Event
|
class PlayerWillBeAdded extends Event
|
||||||
{
|
{
|
||||||
public $playerName;
|
public $playerName;
|
||||||
|
21
app/Events/PlayerWillBeDeleted.php
Normal file
21
app/Events/PlayerWillBeDeleted.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,6 +14,7 @@ use App\Events\PlayerWasAdded;
|
|||||||
use App\Events\PlayerWasDeleted;
|
use App\Events\PlayerWasDeleted;
|
||||||
use App\Events\CheckPlayerExists;
|
use App\Events\CheckPlayerExists;
|
||||||
use App\Events\PlayerWillBeAdded;
|
use App\Events\PlayerWillBeAdded;
|
||||||
|
use App\Events\PlayerWillBeDeleted;
|
||||||
use App\Exceptions\PrettyPageException;
|
use App\Exceptions\PrettyPageException;
|
||||||
use App\Services\Repositories\UserRepository;
|
use App\Services\Repositories\UserRepository;
|
||||||
|
|
||||||
@ -83,10 +84,12 @@ class PlayerController extends Controller
|
|||||||
{
|
{
|
||||||
$player_name = $this->player->player_name;
|
$player_name = $this->player->player_name;
|
||||||
|
|
||||||
|
Event::fire(new PlayerWillBeDeleted($this->player));
|
||||||
|
|
||||||
if ($this->player->delete()) {
|
if ($this->player->delete()) {
|
||||||
$this->user->setScore(Option::get('score_per_player'), 'plus');
|
$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);
|
return json(trans('user.player.delete.success', ['name' => $player_name]), 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user