public function saveGymInfo($id) { $gym = new Gym(); $gym->name = $this->name; // $gym->status = $this->status; $gym->contact = $this->contact; //$gym->logo = $this->logo; $gym->manager = $this->manager; $gym->description = $this->description; $gym->open_time = $this->open_time; $gym->location = $this->location; $gym->wechat = $this->wechat; $gym->support_membercard = $this->support_membercard; $gym->gym_admin_id = $id; $gym->created_at = time(); $gym->updated_at = time(); $gym->area_id = $this->province; $gym->latitude = 4.5; $gym->longitude = 4.7; if ($gym->save()) { $this->gym_id = $gym->id; $sports = $this->sports; foreach ($sports as $sport) { $gym_sports = new GymSports(); $gym_sports->gym_id = $gym->id; $gym_sports->sports_id = $sport; echo 'before gymsports'; echo $gym_sports->sports_id; echo 'end gm'; $gym_sports->created_at = time(); $gym_sports->updated_at = time(); if ($gym_sports->save()) { } else { return false; } next($sports); } return true; } else { echo 'fial'; return false; } }
public function getGymSports() { return $this->hasMany(GymSports::className(), ['gym_id' => 'id']); }