Ejemplo n.º 1
0
 /**
  * @param string $name
  * @param int $groupId
  * @return Power
  * @throws \Exception
  */
 public function createNewPower($name, $groupId)
 {
     if ($name == null || sizeof($name) < 1) {
         throw new \Exception("Invalid power name - null or zero-length");
     }
     // Test that the name is unique
     $power = Power::where('name', '=', $name)->first();
     if ($power != null) {
         throw new \Exception("A power with the name " . $name . " already exists.");
     }
     $group = PowerGroup::find($groupId);
     if ($group == null) {
         throw new \Exception("Unknown power group ID " . $groupId);
     }
     $power = new Power();
     $power->name = $name;
     $power->group = $groupId;
     $power->save();
     return $power;
 }