-1

We have an online-shop.

We can have any friendly urls as for separate models like products or categories (/iphone-6-white = /iphones/23) as for custom filter urls like (/cool-flashes = /flash?cap=32gb&col=white)

What is the best practice to handle all urls?

IMHO we should create a table where we should store two cols (urlFrom and RedirectUrl). But redirect is not good way for us because we do not want a redirect, we just want to show appropriate content under the urlFrom.

I want to store it in a single table to make just one request to DB to find out whether we have the url or not.

Kamil Davudov
  • 363
  • 1
  • 3
  • 15
  • we should not also forget that its important to make a convinient tool to parse redirectUrls. if we catch from /blabla that we should show /categories?col=black&size=2 how we will handle that? – Kamil Davudov Oct 06 '16 at 15:30
  • Use slugs. https://github.com/cviebrock/eloquent-sluggable – Samsquanch Oct 06 '16 at 16:27

1 Answers1

0

You can create submit your form in array such as search[name], search[price][form] and create your custom Middleware that will checks request contain of search[] build url and after that redirect to this page.

Of course after that you must create route for those page, like:

Route::get('/search/{searchName?}/{searchPriceFrom?}', 'ProductsController@search');

Where your RoutesServiceProvoider will look like this:

Route::bind('searchName', function($term) {
    // your DB query and checks...
});
astratyandmitry
  • 471
  • 3
  • 7