我正在研究IP创建形式,并希望爆炸一些数据[关闭]

It's my store method where I am getting IP through request from my view

    public function store(Request $request)
    {
        $ip['ip_range'] = $request->input('ip_range');
        $ip['min_ip']   = $request->input('ip_range');
        $ip['max_ip']   = $request->input('ip_range');

        $ip_data = Ip::create($ip);
        session()->flash('msg', ' Successfully created');
        return view('ip.index');
    }

In above I want if IP comes as

192.168.2.9
192.168.1.2

It should be saved as 2 values .... Mean it should separate it on /r/n and where I found /n I create a new value and so on.

And next thing is that if user enter as

192.168.1.0-3

Here a - comes at last one 192.168.1-3 should be save in ip_range and 192.168.1.0 in min_ip while 192.168.1.3 as max_ip.

I hope this is what you were looking for:

public function store(Request $request) {
    $ip['ip_range'] = $request->input('ip_range');

    $arrIps = explode("
", $ip['ip_range']);
    foreach($arrIps as $strIp) {

        $arrRange=explode("-",$strIp);
        if(count($arrRange)>1){
         $ip['min_ip']= $arrRange[0];
         $arrDot=explode(".",$arrRange[0]);
         $arrDot[3]=$arrRange[1];
         $ip['max_ip']= implode(".",$arrDot);
        }
        else
        $ip['min_ip']=$ip['max_ip']="";

        $ip_data = Ip::create($ip);

    }
    session()->flash('msg', ' Successfully created');
    return view('ip.index');
}