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

elqouent10's avatar

Extract an anonymous function in PHP

How do you extract an anonymous function in PHP and store it in a variable like you can in javascript?

$config = ['prefix' => 'project',  'as' => 'project.',  'middleware' => ['auth'] ]
//I would like to take the second parameter in this group method and store it in a variable or property named "routes"
    Route::group($config, function () {
        Route::get('/load', [
            'as'            =>      'load',
            'uses'          =>      'ProjectController@load'
        ]);
    });

0 likes
2 replies

Please or to participate in this conversation.