from my route i need to pass the value of $page to controller
route:
$app->get('/show/{page}', function($page) use ($app) {
$controller = $app->make('App\Http\Controllers\PageController');
return $controller->index();
});
controller:
public static function index(){
/** how can I get the value of $page form here so i can pass it to the view **/
return view('index')->with('page', $page);
}
You could pass it as a parameter of the index function.
Route
$app->get('/show/{page}', function($page) use ($app) {
$controller = $app->make('App\Http\Controllers\PageController');
return $controller->index( $page );
});
Although the route looks wrong to me, normally you define the route without a forward slash at the beggining: $app->get('show/{page}', ...
.
Controller
public static function index($page)
{
return view('index')->with('page', $page);
}
Unless there is a reason for using a closure, your route could be re-written as below, and the {$page}
variable will automatically be passed to the controller method as a parameter:
Route
$app->get('show/{page}', [
'uses' => 'App\Http\Controllers\PageController@index'
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With