Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I mount a POST route? #177

Open
rvrbk opened this issue Apr 9, 2022 · 3 comments
Open

Can I mount a POST route? #177

rvrbk opened this issue Apr 9, 2022 · 3 comments

Comments

@rvrbk
Copy link

rvrbk commented Apr 9, 2022

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?

@BaseMax
Copy link

BaseMax commented Apr 10, 2022

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

@rvrbk
Copy link
Author

rvrbk commented Apr 10, 2022

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.

@Edydeyemi
Copy link

Edydeyemi commented May 25, 2022

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');

})`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants