Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jericopulvera's avatar

How to CMS route URI.

Hello I'm making a CMS for each menu item.

  • When admin changes the Main text it should also change the URI name.
  • so when the admin changes the pages name it should also change the URI name
  • for example my menu name is called hello. it would look like this in the link sitename.com/menu/hello
  • then when the admin changes the menu name with a space it would become like this sitename.com/menu/New%20Menu
  • it doesn't look good in my opinion I wanted it to became like sitename.com/menu/new-menu

This is my route


    $data = App\Models\PageMeta::where('page_id', 2)->get();
    $menu2= $data->where('name', 'family_header_text')->first()->meta_data == '' ? 'hello : $data->where('name', 'hello_header_text')->first()->meta_data;

    Route::get($menu2, ['as' => $menu2, 'uses' => 'SiteController@getSecondMenu']);
       Route::post('cms/second-menu', ['as' => 'save-second-menu, 'uses' => 'Backend\CMSController@saveSecondMenu]);
0 likes
1 reply
spekkionu's avatar

The problem with adding a route for each page is that it will scale poorly if you have a large amount of pages.

First it will have to create route objects for each page and those will be stored in memory on every request.

Then when it tries to match against the routes it checks the url against each one until it finds a match. If there are a huge amount of them this can cause requests to be slow if the matching route is toward the end of the list.

What I would do is add a "catch all" route at the end of your routes file that matches against anything.

In the controller for this route try to pull a page for that url and if none is found return a 404 response.

Please or to participate in this conversation.