salamwaddah's avatar

What controller should be responsible for static pages?

I'm trying to avoid returning a View directly from routes and give that responsibility to controllers. What controller or what should be the controller name that handles static HTML pages like about us, privacy policy, etc.

?? StaticPageController, PageController, AboutUsController, PrivacyPolicyController ??

0 likes
6 replies
STEREOH's avatar

I would use either of the two first options you cited.

The 2 last options are too specific and you don't want to create a controller for each static page you create.

Just create a StaticPageController (or PageController) and redirect your route to a specific method in it.

1 like
tykus's avatar
tykus
Best Answer
Level 104

Personally, I would use the Router's view method over a controller, it is clear what it does, and does not rely on creating a dumb controller as a dumping ground for these pages:

Route::view('about-us', 'static/about-us');
1 like
STEREOH's avatar

@TYKUS - I like this approach too.

I only use a controller to get some data on some of my pages, but I can agree that if you only need a purelly static page there's no need for it.

Snapey's avatar

I use a PagesController and pass in the name of the view

Route::get('{page}', 'pagesController@show');

PagesController

public function show($page)
{

    abort_unless(View::exists('pages.' . page), 404);

    return view('pages.' . $page);

}

put this route after others. It will be greedy

or, just use Route::view !

2 likes
shez1983's avatar

i do the same as @snapey but just prefix the url with pages/ or something...

Please or to participate in this conversation.