Tuesday, May 23, 2017

Create Domain that have valid format and skip others

I am working on storing functionality of domains in laravel 5.3. Here user enter multiple domains in textarea one per line I want to validate each domain with right format should be create and other should be skipped and also count with correct format and bad format. here is my code

$name = $request->input('domain_name');
   $domains = preg_split('/[\r\n ,]+/', $name);

    foreach($domains as $domain){
      $data['domain']   = $domain;
      $data['user_id']  = Auth::user()->id;
     if (empty($request->input('domain_id'))){
        $domain = Domain::create($data);
      }
    }

Domain name with correct format should create and skip bad format and count both correct and incorrect formats. Thanks for Help



via blue moon

Advertisement