lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.52k stars 124 forks source link

Automate command registration #112

Closed keyurshah closed 3 years ago

keyurshah commented 3 years ago

Hello,

Currently after running the make command, I go to the Kernel file to register the class in the console.

Would there be any benefit to having actions be automatically registered so that the registration step can be skipped?

Trying to minimize the number of files that need to be touched after add a new action.

I primarily use yii/craft cms, and one nice feature is that there is automatic url generation for files (which can be changed if needed).

So it would be interesting if any action had automatic route generation based on the file/folder path. Same for views. Relying on convention over configuration.

Just wanted to bring it up for discussion. I'm really enjoying using this project!

Thanks!

leandrodiogenes commented 3 years ago

Hi @keyurshah . Check this session https://laravelactions.com/2.x/as-controller.html#routes

lorisleiva commented 3 years ago

Hi there 👋

Sorry for the late reply. As @leandrodiogenes mentioned, this is possible for route registrations but not yet for command registrations.

It used to be possible on v1 because that was the only way to register them but now that Actions can be directly registered as commands, one can easily create a script that auto-register them by going through a folder.

Technically you could use the load method on the Console Kernel but the issue is that it ensures the class is an instance of Command so it won't work for your lambda actions.

I'd like to have a registerCommands method with the same signature as the registerRoutes at some point to facilitate that. I'll leave this issue open until such method exists and is documented. 🙂

lorisleiva commented 3 years ago

Okay I've decided to implement this now haha.

It's done, released as v2.1.4 and documented. 🚀

keyurshah commented 3 years ago

Thanks! This is perfect. Just catching up with this issue