Closed tommica closed 1 month ago
I really like this, but would also like the ability to set the route. The routes can be auto registered when the actions are registered. What do you think?
@edalzell Yeah, that could be neat - do you have any time to add that to the codebase?
@edalzell Yeah, that could be neat - do you have any time to add that to the codebase?
Not right now I don't, sorry. Trying to get a new SaaS app out the door.
More ideas, like Livewire/Spatie Data, we could use PHP attributes perhaps for this, or separate properties.
Closing due to inactivity. If you feel your issue is still relevant please reopen it.
It feels a bit archaic to have to define routes for the actions, so rather than having to do that explicitly for each route, there is now a generic route for it:
/laravel-actions/{actionString}
- the idea is this:I have a simple form that saves the blog post, and instead of using "route(...)" helper, we use the new "action_route(...)" helper like this:
When the route gets generated, the name of the action will be encrypted, to avoid any kind of shenanigans in regards of people trying to invoke any other action that they should not, f.x "MarkAsAdmin".
Under the hood this request will be handled by
ActionController
with thisRoute::any('laravel-actions/{actionString}', \Lorisleiva\Actions\ActionController::class)->name('laravel-actions.route');
definition, which will decrypt the action name and will call the defined action and return the result for it.You can also generate the route to use some explicit functions if you want by doing something like this:
You can also use it in a link: