router icon indicating copy to clipboard operation
router copied to clipboard

Can I mount a POST route?

Open rvrbk opened this issue 3 years ago • 3 comments

The following code works:

$router->post('/api/social/contact', 'SocialController@contact');

But this code doesn't:

$router->mount('/api', function() use($router) {
    $router->mount('/social', function() use($router) {
        $router->post('/contact', 'SocialController@contact');
    });
});

Note that there is no method specified in the mount statement.

Am I missing something?

rvrbk avatar Apr 09 '22 17:04 rvrbk

Hey Rik, What do you mean by mounting a new route inner a route? Do you want to group the prefix routes?

BaseMax avatar Apr 10 '22 06:04 BaseMax

Hi BaseMax,

That's indeed what I want to do, the above method works with get() requests but not if there's a child post() request.

rvrbk avatar Apr 10 '22 07:04 rvrbk

Why don't you make it this way $router->mount('/api/social', function () use ($router) { $router->post('/contact', 'SocialController@contact'); }); ``

This way, you can add multiple subroutes under the api/social route like this:

$router->mount('/api/social', function () use ($router) {

 $router->post('/contact', 'SocialController@contact');
   
 $router->get('/friends', 'SocialController@friends');
    
 $router->post('/add-friend', 'SocialController@addFriend');

})`

Edydeyemi avatar May 25 '22 09:05 Edydeyemi