user1327 user1327 - 1 year ago 108
PHP Question

Proper way to pass a hard-coded value from route to controller (Laravel)?

I have a

with one action:
This action accepts a

What I want to achieve:

Have a routes
When one of this routes is triggered, pass a value predefined in routes file to

In my routes file:

Route::get('about', function () {
return App::make('App\Http\Controllers\PagesController')->view('about');

Route::get('foobar', function () {
return App::make('App\Http\Controllers\PagesController')->view('foobar');

It works as expected, but I want to know is there a better and more proper way to achieve the same functionality?

Answer Source

Pass your pages as route parameter:

Route::get('{page}', 'PagesController@view');

public function view($page)
    //$page is your value passed by route;
    return view($page);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download