0

In Laravel 10, I have routes that are structured like the following:

Route::group(['middleware' => ['permission:edit-settings']], function () {
    $module_name = 'settings';
    $controller_name = 'SettingController';

    Route::get("$module_name/{settingModule?}", "$controller_name@index")
});

I have tried with

Route::get("$module_name/{settingModule?}", "$controller_name@index")->name(function ($parameters) {
    $settingModule = $parameters['settingModule'] ?? 'settings';
    return $settingModule . 'index';
});

My requirement is to generate the route name dynamically based on the route parameter, but it throws an error:

Object of class Closure could not be converted to string

3
  • 1
    You cannot pass a closure to ->name(), it has to be a string. Commented Jun 16, 2023 at 6:57
  • @Remul, I think you are right, i am unable to find an answer anywhere. Commented Jun 16, 2023 at 7:03
  • routes are save in memory during runtime, It should not be possible to pass the route paramater as part of route name because that never existed until someone makes a request to that specific route. and even if its possible, imagine someone doing a thousand, or a million request to that route with unique param each, your application will keep storing it and your poor memory will explode lol Commented Jun 16, 2023 at 8:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.