Exemplo n.º 1
0
 public static function create(array $attributes = [])
 {
     $country = parent::create($attributes);
     /** @var $country Country */
     $army = Army::create(['size' => 2]);
     $country->army()->save($army);
     return $country;
 }
Exemplo n.º 2
0
 /**
  * 'game/armies/{id}/upgrade' - POST AJAX запрос для улучшения армии.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function postArmyUpgrade($id)
 {
     try {
         $army = Army::find($id);
         $army->castle()->first()->calcCastleIncreaseResources();
         $army->upgrade();
     } catch (\Exception $exc) {
         return $this->ajaxError($exc->getMessage());
     }
     return $this->ajaxResponse(['army' => $army, 'squads' => $army->squads]);
 }