public function postEdit($id)
 {
     if (!$this->checkRoute()) {
         return Redirect::route('index');
     }
     $title = 'Edit A Server Code - ' . $this->site_name;
     $input = Input::only('name', 'deck', 'description', 'slug');
     $server_tag = ServerTag::find($id);
     $messages = ['unique' => 'This server tag already exists in the database!'];
     $validator = Validator::make($input, ['name' => 'required|unique:server_tags,name,' . $server_tag->id, 'deck' => 'required'], $messages);
     if ($validator->fails()) {
         return Redirect::action('ServerTagController@getEdit', [$id])->withErrors($validator)->withInput();
     }
     $server_tag->name = $input['name'];
     $server_tag->deck = $input['deck'];
     $server_tag->description = $input['description'];
     $server_tag->last_ip = Request::getClientIp();
     if ($input['slug'] == '' || $input['slug'] == $server_tag->slug) {
         $slug = Str::slug($input['name']);
     } else {
         $slug = $input['slug'];
     }
     $server_tag->slug = $slug;
     $success = $server_tag->save();
     if ($success) {
         //Cache::tags('modpacks')->flush();
         //Queue::push('BuildCache');
         return View::make('tags.server.edit', ['title' => $title, 'success' => true, 'server_tag' => $server_tag]);
     }
     return Redirect::action('ServerTagController@getEdit', [$id])->withErrors(['message' => 'Unable to edit modpack code.'])->withInput();
 }
 public function getServers($modpack_slug = null)
 {
     $query_array = [];
     $selected_tags = [];
     $selected_country = false;
     $selected_permission = false;
     $selected_modpack = $modpack_slug;
     $modpack_line = 'for all Modpacks, ';
     $tag_line = 'with any tags, ';
     $country_line = 'in any country, ';
     $permission_line = 'and with any permission.';
     $permissions_array = ['whitelist' => "Whitelist", 'greylist' => "Greylist", 'open' => "Open"];
     $id_permissions_array = ['whitelist' => 1, 'greylist' => 2, 'open' => 3];
     $input = Input::only('tags', 'country', 'permission');
     $countries = Server::countryList();
     $tags = ServerTag::all();
     $table_javascript = route('tdf', ['servers', 'all']);
     if (!$modpack_slug) {
         $title = 'Modded Minecraft Servers - ' . $this->site_name;
         $meta_description = 'Modded Minecraft servers for all the packs we list. With powerful searching and filtering.';
         $modpack_name = null;
     } else {
         $modpack = Modpack::where('slug', $modpack_slug)->first();
         if (!$modpack) {
             return Redirect::to(action('ServerController@getServers'));
         }
         $title = $modpack->name . ' Servers - ' . $this->site_name;
         $meta_description = 'Minecraft Servers for the ' . $modpack->name . ' modpack. With powerful searching and filtering.';
         $modpack_name = $modpack->name;
         $modpack_line = 'for ' . $modpack->name . ', ';
         $query_array[] = 'modpack=' . $modpack->id;
     }
     if ($input['tags']) {
         $tags_array = [];
         $tag_names = [];
         $tags_javascript_string = '';
         $tag_line = 'including the tags ';
         foreach ($tags as $t) {
             $tags_array[$t->slug] = $t->id;
             $tag_names[$t->slug] = $t->name;
         }
         $exploded_tags = explode(',', strtolower($input['tags']));
         foreach ($exploded_tags as $t) {
             if (array_key_exists($t, $tags_array)) {
                 $tags_javascript_string .= $tags_array[$t] . ',';
                 $selected_tags[] = $t;
                 $tag_line .= $tag_names[$t] . ', ';
             }
         }
         $tag_line = rtrim($tag_line, ', ') . ', ';
         $query_array[] = 'tags=' . rtrim($tags_javascript_string, ',');
     }
     if ($input['country']) {
         $country_code = $input['country'];
         $query_array[] = 'country=' . $country_code;
         $selected_country = $country_code;
         $country_line = 'in ' . $countries[$country_code] . ', ';
     }
     if ($input['permission']) {
         $permission = $input['permission'];
         $query_array[] = 'permission=' . $id_permissions_array[$permission];
         $selected_permission = $input['permission'];
         $permission_line = 'and with ' . strtolower($permissions_array[$permission]) . ' permissions.';
     }
     $query_count = 0;
     foreach ($query_array as $q) {
         if ($query_count == 0) {
             $table_javascript .= '?';
         } else {
             $table_javascript .= '&';
         }
         $table_javascript .= $q;
         $query_count++;
     }
     $display_line = 'Displaying servers ' . $modpack_line . $tag_line . $country_line . $permission_line;
     return View::make('servers.list', ['title' => $title, 'meta_description' => $meta_description, 'table_javascript' => $table_javascript, 'modpack_name' => $modpack_name, 'countries' => $countries, 'chosen' => true, 'permissions' => $permissions_array, 'selected_tags' => $selected_tags, 'selected_country' => $selected_country, 'selected_permission' => $selected_permission, 'selected_modpack' => $selected_modpack, 'display_line' => $display_line]);
 }