public static function boot() { parent::boot(); User::deleting(function ($user) { if (App::environment('local')) { Stripe::setApiKey(Config::get('stripe.development.secret')); } else { Stripe::setApiKey(Config::get('stripe.production.secret')); } $cu = \Stripe\Customer::retrieve($user->stripe_customer_id); $cu->delete(); return true; }); }
use UserTrait; const GHOST = "Fantôme"; protected $hidden = array('password'); public function players() { return $this->hasMany('Player', 'user'); } public function playersButFantom() { return $this->hasMany('Player', 'user')->where('players.name', '<>', User::GHOST); } public static function fantom() { return Player::where('name', '=', User::GHOST)->where('user', '=', Auth::user()->id)->first(); } public function tournaments() { return $this->hasMany('Tournament', 'user'); } public function maps() { return $this->hasMany('Map', 'user'); } } User::deleting(function ($user) { $tournaments = $user->tournaments()->get(); foreach ($tournaments as $tournament) { $tournament->delete(); } $user->players()->delete(); });