php - Laravel 5: Passing additional parameters to Controller -
i using laravel 5 build website , have few pages, content written in blade (e.g. about, terms , conditions etc.) , others pulled database (general blog posts).
i'd write single controller , run switch case show specific view.
e.g.
pagescontroller@showpage
:
public function showpage($page){ switch ($page) { case 'about': $view = 'frontend.about'; break; case 'terms': $view = 'frontend.terms'; break; ... default: $view = 'frontend.home' break; } return view($view); }
but how can pass additional parameter in routes.php
?
//route page route::get('/about',['as'=>'about','uses'=>'pagescontroller@showpage']); //route terms route::get('/terms',['as'=>'terms','uses'=>'pagescontroller@showpage']);
something like:
//route terms route::get('/terms',['as'=>'terms','uses'=>'pagescontroller@showpage'])->with(['page'=>'terms']);
it easy pass variable in route. take @ following code.
route::get('/terms/{page}',['as'=>'terms','uses'=>'pagescontroller@showpage']);
and can access value inside controller action following example.
function showpage($page){ echo $page; }
Comments
Post a Comment