Example #1
0
 public static function boot()
 {
     parent::boot();
     static::created(function (User $user) {
         $castle = $user->castle()->create(['name' => $user->caste_name ?: $user->name]);
         $cb = CommentBlock::create();
         $cb->save();
         $user->commentBlock()->associate($cb);
         $user->save();
         // Задать позицию на карте и армию по-умолчанию.
         $location = Location::freeRandom();
         if (is_null($location)) {
             throw new GameException('Нельзя добавить новый замок. Все поле уже занято.');
         }
         $location->castle()->associate($castle);
         $location->save();
         $castle->army()->create(['name' => "{$castle->name}'s army", 'size' => 15, 'level' => 1]);
         // Создаем сооружения
         $castle->createBuildings();
         // Инициализировать ресурсы в замке
         $castle->initResources();
     });
     static::updated(function (User $user) {
         $castle = $user->castle;
         $castle->name = $user->castle_name;
         $castle->save();
     });
 }
Example #2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $avatar = Avatar::create(['mustache_id' => 1, 'amulet_id' => 1, 'hair_id' => 1, 'flag_id' => 1]);
     $cb = CommentBlock::create();
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'avatar_id' => $avatar->id, 'comment_block_id' => $cb->id]);
 }