I thought I solved my problem. Here's how I thought I fixed it:
Instead of:
Game::create([
'slug' => 'playstation/alien-isolation',
'platform' => 'playstation',
'name' => 'Alien Isolation',
'price' => '£19.99',
'description' => 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt debitis, amet magnam accusamus nisi distinctio eveniet ullam. Facere, cumque architecto.',
'image' => '/storage/images/playstation/alien_isolation.jpeg'
]);
I used the slug method:
Game::create([
'slug' => Str::slug('Alien Isolation', '-'),
'platform' => 'playstation',
'name' => 'Alien Isolation',
'price' => '£19.99',
'description' => 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt debitis, amet magnam accusamus nisi distinctio eveniet ullam. Facere, cumque architecto.',
'image' => '/storage/images/playstation/alien_isolation.jpeg'
]);
This worked while I had this in my controller:
public function show($slug)
{
$game = Game::where('slug', $slug)->first();
return view('products.game')->with([
'game' => $game
]);
}
and this in my web.php:
Route::get('/playstation/{slug}', 'PlaystationController@show');
By 'worked', I mean it returned the data according to the corresponding slug of the page and the slug in the database. Unfortunately, as soon as I refresh the page, I get a 404.
This makes absolutely no sense to me but I am new to this.
I also don't understand how this can possibly work at all when I run my data dump method and get a response of 'null':
$game = Game::where('slug', $slug)->first();
dd($game);
Why would I be getting a 404 but only after refreshing the page? There are so many things I'm confused about here. Does anyone know why this may be?
Thanks