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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -