/** * Run the database seeds. * * @return void */ public function run() { $subdomains = json_decode(file_get_contents(stryve_path() . '/Database/SeedData/reserved_subdomains.json')); $subdomains_array = []; foreach ($subdomains as $subdomain) { $subdomain = lowertrim($subdomain); if (isValidSubdomain($subdomain)) { $subdomains_array[] = ['subdomain' => $subdomain, 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]; } } $this->reserved_subdomain->insert($subdomains_array); }
/** * Determines whether or not the provided subdomain * meets subdomain length and character requirements. * * @param string $subdomain * @return bool */ public function isValidSubdomain($subdomain) { $subdomain = lowertrim($subdomain); $min_length = Config::get('stryve.tenant.subdomain-min-length'); $max_length = Config::get('stryve.tenant.subdomain-max-length'); $subdomain_length = strlen($subdomain); // check subdomain is of valid characters if (!isValidSubdomain($subdomain)) { return false; } // check subdomain meets length requirements if ($subdomain_length < $min_length || $subdomain_length > $max_length) { return false; } return true; }