D
D
driverx182017-08-21 19:31:50
Laravel
driverx18, 2017-08-21 19:31:50

What is the best way to organize routing with pages of the same type?

I've only been in Laravel for a couple of days, I work with a ready-made layout, and the site has pages like "Contacts", "Details", "Photos" - that is, pages of the same type, static. Somehow I think that for all of them to write something like this:

Route::get('photos', '[email protected]');
Route::get('contacts', '[email protected]');

will not be entirely correct, because there can be a dozen such pages. So - how is it better to organize the routing of such static pages in Laravel?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Aksentiev, 2017-08-21
@Sanasol

page/{section}

D
D3lphi, 2017-08-21
@D3lphi

If you can have many of the same type of static pages, then make a separate route for them: The user will follow the site.com/page/photos link , and you will pull the photos page from the database.

A
Alex Wells, 2017-08-22
@Alex_Wells

As stated above, page/{section}, adding to the route the condition where('section', '(photos|contacts|other_static_page)');
In the controller, you can safely return view('pages.' . $section);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question