lorisleiva / laravel-actions

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

Action::registerCommands() in console only? #148

Closed joelmellon closed 2 years ago

joelmellon commented 2 years ago

I decided to only register my Action Commands automatically when the app is running in the console, like so:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if ($this->app->runningInConsole()) {
            // automatically load and register any App\Action\* classes that have Artisan command functionality
            \Lorisleiva\Actions\Facades\Actions::registerCommands();
        }
    }
}

Are there any pros/cons to this approach?

Cons:

Pros:

To me the cons to this approach aren't really considerations, since I don't need to (and probably shouldn't be) calling Actions as Commands anywhere but the console.

Anyway, what led me to this question was that if there's no significant benefit from executing commands outside the console context, this (my code block above) should be the documented way to auto-register commands here.

Any thoughts or objections?

joelmellon commented 2 years ago

I made a PR here.

lorisleiva commented 2 years ago

I agree and merged that PR, Thanks! 👌