merge($this->cidrToRange()); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'cidr' => ['required', new CidrRule()], 'first_ip' => 'required|ipv4', 'last_ip' => 'required|ipv4' ]; } /** * cidr To Ranges * * @return array ['first_ip', 'last_ip'] */ private function cidrToRange(): array { $first_ip = ''; $last_ip = ''; $cidr = collect(explode('/', \strval($this->cidr))); try { $first_ip = long2ip(intval(ip2long($cidr->get(0))) & ((-1 << (32 - intval($cidr->get(1)))))); $last_ip = long2ip(intval(ip2long(\strval($first_ip))) + pow(2, (32 - intval($cidr->get(1)))) - 1); } catch (\Error $e) { Session::flash('warning', trans('Le CIDR est mal formé')); } return \compact('first_ip', 'last_ip'); } }