-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
Ability to define resourceful Action routes #295
base: main
Are you sure you want to change the base?
Conversation
+1 |
Couldn't this also be its own package? |
Furthermore, could you please add tests? |
@Wulfheart happy to wrap this up into it's own package if the community believes it'll be useful. Where else can you see this being useful away from the Laravel Actions package?
Of course, will add some test coverage for this 👍 |
…erride Action class name generation
@Wulfheart @lorisleiva any thoughts? |
I don't mind adding this. I think it's well tested and could benefit some people but I find the name of the macro confusing. We already have a way of registering routes within actions by doing I'd rather have a slightly more lengthy macro name that better describes the operation such as |
How would we define the individual namespaces if Actions are not in the app/Actions dir, how could we specify
as an example, and how can we tackle nesting/shallow nesting? I personally think we should keep resourceful actions as solely defined in route files for the above reasons |
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.
I'm happy to go with Route::resourceActions
.
} | ||
|
||
if (empty($actionClass)) { | ||
$actionClass = match ($method) { |
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.
Can $method
be a value that isn't listed in the match values?
I absolutely love this package, but the only thing I don't like is having to declare all of my Action routes individually, and losing the ability to define resourceful routes.
This PR attempts to achieve this, by leveraging the
Route::resource()
function and swaping out theController@action
for the action class.Example usage:
The benefit of this is that it will force developers to have consistent routing AND consistent Action naming. Now the names of these are up for grabs, but I've gone for:
GetAddresses
- this replacesController@index
ShowCreateAddress
- this replacesController@create
ShowAddress
- this replacesController@show
ShowEditAddress
- this replacesController@edit
CreateAddress
- this replacesController@store
UpdateAddress
- this replacesController@update
DeleteAddress
- this replacesController@destroy
Example - the following two route declarations:
produces the following routes:
As I mentioned above, if the Action is under a different namespace, we can specify that:
which produces: