Before using laravel, usually I route my page using code like this:
//index.php $get_page=$_GET['page']; if (empty($get_page) or $get_page=='dashboard') { include ('content/dashboard.php'); }elseif ($get_page=='schedule') { include ('content/schedule.php'); } else{ include ('404/404.php'); }
Is there anyway that I can route my page like that but in Laravel? I prefer to use format : www.example.com/?page=schedule rather than www.example.com/schedule
Advertisement
Answer
Route::get('/', function (Request $request) { if($request->query('page')) { $page = $request->query('page'); return view($page); } });
Documentation: https://laravel.com/docs/8.x/routing