Пример #1
0
 public function postAdd($version)
 {
     if (!$this->checkRoute()) {
         return Redirect::route('index');
     }
     $url_version = $version;
     $version = $this->getVersion($version);
     $title = 'Add A Modpack - ' . $this->site_name;
     $minecraft_version = MinecraftVersion::where('name', '=', $version)->first();
     $input = Input::only('name', 'launcher', 'mods', 'tags', 'creators', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug');
     $messages = ['unique' => 'This mod already exists in the database. If it requires an update let us know!', 'url' => 'The :attribute field is not a valid URL.'];
     $validator = Validator::make($input, ['name' => 'required|unique:modpacks,name', 'launcher' => 'required', 'mods' => 'required', 'creators' => 'required', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages);
     if ($validator->fails()) {
         return Redirect::action('ModpackController@getAdd', [$url_version])->withErrors($validator)->withInput();
     }
     $modpack = new Modpack();
     $modpack->name = $input['name'];
     $modpack->launcher_id = $input['launcher'];
     $modpack->minecraft_version_id = $minecraft_version->id;
     $modpack->deck = $input['deck'];
     $modpack->website = $input['website'];
     $modpack->download_link = $input['download_link'];
     $modpack->donate_link = $input['donate_link'];
     $modpack->wiki_link = $input['wiki_link'];
     $modpack->description = $input['description'];
     if ($input['slug'] == '') {
         $slug = Str::slug($input['name']);
     } else {
         $slug = $input['slug'];
     }
     $modpack->slug = $slug;
     $modpack->last_ip = Request::getClientIp();
     $success = $modpack->save();
     if ($success) {
         foreach ($input['creators'] as $creator) {
             $modpack->creators()->attach($creator);
         }
         foreach ($input['mods'] as $mod) {
             $modpack->mods()->attach($mod);
         }
         foreach ($input['tags'] as $tag) {
             $modpack->tags()->attach($tag);
         }
         $mods = $minecraft_version->mods;
         foreach ($mods as $mod) {
             $id = $mod->id;
             $mod_select_array[$id] = $mod->name;
         }
         Cache::tags('modpacks')->flush();
         Cache::tags('modpackmods')->flush();
         Cache::tags('modmodpacks')->flush();
         Queue::push('BuildCache');
         return View::make('modpacks.add', ['title' => $title, 'chosen' => true, 'success' => true, 'version' => $version, 'url_version' => $url_version, 'mods' => $mod_select_array]);
     }
     return Redirect::action('ModpackController@getAdd', [$url_version])->withErrors(['message' => 'Unable to add modpack.'])->withInput();
 }