Esempio n. 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     Console::create(['name' => 'Sony Playstation 4', 'short_name' => 'PS4']);
     Console::create(['name' => 'Microsoft Xbox One', 'short_name' => 'Xbox One']);
     Console::create(['name' => 'Nintendo Wii U', 'short_name' => 'Wii U']);
     Console::create(['name' => 'PC', 'short_name' => 'PC']);
     Console::create(['name' => 'Sony Playstation Vita', 'short_name' => 'PS Vita']);
     Console::create(['name' => 'Nintendo 3DS', 'short_name' => '3DS']);
     Console::create(['name' => 'Sony Playstation 3', 'short_name' => 'PS3']);
     Console::create(['name' => 'Microsoft Xbox 360', 'short_name' => 'Xbox 360']);
     Console::create(['name' => 'Nintendo Wii', 'short_name' => 'Wii']);
 }
 public function addNewGame(Request $request)
 {
     if (Auth::guest()) {
         flash()->error("You need to be logged in to add a game");
         return redirect()->back();
     }
     $game = new Game();
     $game->popularity = 0;
     // !
     // Check if console exists
     $console = Console::where('name', $request->console)->first();
     if (!$console) {
         flash("Something went wrong.");
         return redirect()->back();
     }
     // Check if game is already in the database
     $alreadyThereGame = Game::where('title', $request->input('title'))->where('console_id', $console->id)->first();
     if ($alreadyThereGame) {
         // Redirect users to the game page that's already theree
         return redirect()->route('game', ['slug' => $alreadyThereGame->slug]);
     }
     $game->console_id = (int) $console->id;
     // !
     $game->title = $request->input('title');
     // !
     $slug = $request->input('title');
     $slug = str_limit($slug, 40) . "-" . $console->short_name;
     $slug = str_slug($slug);
     $slug = strtolower($slug);
     $game->slug = $slug;
     // !
     // Stores the boxart in S3 servers
     if ($request->input('boxart_url')) {
         $boxart = Image::make($request->input('boxart_url'))->resize(350, null, function ($constraint) {
             $constraint->aspectRatio();
         })->encode(pathinfo($request->input('boxart_url'), PATHINFO_EXTENSION));
         $filename = $slug . "-" . str_random(5) . "." . pathinfo($request->input('boxart_url'), PATHINFO_EXTENSION);
         Storage::put($filename, (string) $boxart);
         $game->boxart = $filename;
         // !
     }
     $game->save();
     return redirect()->route('game', ['slug' => $slug]);
 }
 public function index()
 {
     $data['consoles'] = Console::all();
     return view('admin.index', $data);
 }