-
Notifications
You must be signed in to change notification settings - Fork 783
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
[11.x] Refactor routes to dedicated file #1464
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Route; | ||
|
||
Route::post('/token', [ | ||
'uses' => 'AccessTokenController@issueToken', | ||
'as' => 'token', | ||
'middleware' => 'throttle', | ||
]); | ||
|
||
Route::middleware(['web', 'auth'])->group(function () { | ||
Route::post('/token/refresh', [ | ||
'uses' => 'TransientTokenController@refresh', | ||
'as' => 'token.refresh', | ||
]); | ||
|
||
Route::get('/authorize', [ | ||
'uses' => 'AuthorizationController@authorize', | ||
'as' => 'authorizations.authorize', | ||
]); | ||
|
||
Route::post('/authorize', [ | ||
'uses' => 'ApproveAuthorizationController@approve', | ||
'as' => 'authorizations.approve', | ||
]); | ||
|
||
Route::delete('/authorize', [ | ||
'uses' => 'DenyAuthorizationController@deny', | ||
'as' => 'authorizations.deny', | ||
]); | ||
|
||
Route::get('/tokens', [ | ||
'uses' => 'AuthorizedAccessTokenController@forUser', | ||
'as' => 'tokens.index', | ||
]); | ||
|
||
Route::delete('/tokens/{token_id}', [ | ||
'uses' => 'AuthorizedAccessTokenController@destroy', | ||
'as' => 'tokens.destroy', | ||
]); | ||
|
||
Route::get('/clients', [ | ||
'uses' => 'ClientController@forUser', | ||
'as' => 'clients.index', | ||
]); | ||
|
||
Route::post('/clients', [ | ||
'uses' => 'ClientController@store', | ||
'as' => 'clients.store', | ||
]); | ||
|
||
Route::put('/clients/{client_id}', [ | ||
'uses' => 'ClientController@update', | ||
'as' => 'clients.update', | ||
]); | ||
|
||
Route::delete('/clients/{client_id}', [ | ||
'uses' => 'ClientController@destroy', | ||
'as' => 'clients.destroy', | ||
]); | ||
|
||
Route::get('/scopes', [ | ||
'uses' => 'ScopeController@all', | ||
'as' => 'scopes.index', | ||
]); | ||
|
||
Route::get('/personal-access-tokens', [ | ||
'uses' => 'PersonalAccessTokenController@forUser', | ||
'as' => 'personal.tokens.index', | ||
]); | ||
|
||
Route::post('/personal-access-tokens', [ | ||
'uses' => 'PersonalAccessTokenController@store', | ||
'as' => 'personal.tokens.store', | ||
]); | ||
|
||
Route::delete('/personal-access-tokens/{token_id}', [ | ||
'uses' => 'PersonalAccessTokenController@destroy', | ||
'as' => 'personal.tokens.destroy', | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@driesvints hello, why did you not move the group declaration to
web.php
?In that case you can avoid useless
Route::group
declaration if routes are cached (condition inside$this->loadRoutesFrom()
).And this method will look like:
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do this mostly in our packages. It's fine I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I've checked all laravel packages with the route files and think that the core team avoids using
config
insideroute
files, but I saw that you do it. And also we have duplicated conditions in that way.For example horizon package:
https://github.com/laravel/horizon/blob/5.x/src/HorizonServiceProvider.php#L54
there is we have the condition which already exists inside the
loadRoutesFrom
methodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@siarheipashkevich this condition was added in laravel/horizon#1367 only recently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@driesvints thanks, but I think we should optimize this for avoiding extra time of code execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@driesvints in another laravel packages we have also duplicates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine really.