I'm getting error 500 when I try visit a dynamic route. The parameter is optional and is working well when I avoid it.
This is the code
Route::get('/{slug?}', function ($request = '') {
$code = empty($request)? '47ZH2' : $request;
return view('home', ['code' => $code]);
})->where('slug','^([0-9A-Za-z\-]+)?');
Even I tried without regex but is not working anyway.