JBF
2 months ago
378
11
Laravel

Passing variables to the controller but not from the URI

Posted 2 months ago by JBF

For instance you have 3 static pages, index, about and contact. Each just has a view but you don't want to return that from the route because you want to use route caching.

Instead of making a controller method for each page, is it possible to do something like this in the web.php ...

Route::get('/', '[email protected]', ['page' => 'index']);
Route::get('/about', '[email protected]', ['page' => 'about']);
Route::get('/contact', '[email protected]', ['page' => 'contact']);

And then the controller method

public function showpage(Request $request, $page)
{
	return view($page);
}

I know the above doesn't work but hopefully it illustrates my point. Thanks!

Please sign in or create an account to participate in this conversation.