1

Now I am writing routes like this:

Route::group(['prefix' => 'v2/'], function(){
    Route::post('/reg', 'UserController@reg');
    Route::post('/login', 'UserController@login');
    ...
});

Is there any way to make routes like this :

Route::group(['prefix' => 'v2/'], function(){
    Route::group(['uses' => 'UserController'], function(){
        Route::post('/reg', '@reg');
        Route::post('/login','@login');
        ...
    });
});

2 Answers 2

1

Not that I know of, but you could do this

Route::controller('v2', 'UserController');

So now you should have in your controller methods getReg, and postLogin and they would be at same routes as you described.

GET /v2/reg -> UserController@getReg
POST /v2/login -> UserController@postLogin
Sign up to request clarification or add additional context in comments.

2 Comments

How to add middleware ?
1

You can use Implicit Controllers instead.

Your controller method names should begin with the HTTP verb they respond to followed by the URI you want.

For example: postLogin method will respond to POST /login.

Route::controller('v2', 'UserController', [
   'postReg' => 'user.reg',
   'postLogin' => 'user.login',
]);

Comments

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.