Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Artisan commands bridge #46

Description

@kadirgun

Hello, I created such a solution to run artisan commands according to context configs.

namespace App\Providers;

use Illuminate\Support\Str;
use Artificertech\FilamentMultiContext\ContextServiceProvider;
use Filament\FilamentServiceProvider;

class FilamentBlogServiceProvider extends ContextServiceProvider {
    public static string $name = 'filament-blog';

    public function boot(): void {
        if ($this->app->runningInConsole()) {
            $this->registerCommands();
        }

        parent::boot();
    }

    protected function registerCommands(): void {
        $filamentCommands = (new FilamentServiceProvider($this->app))->getCommands();

        $commands = [];

        foreach ($filamentCommands as $class) {
            /**
             * @var \Illuminate\Console\Command $command
             */
            $command = new $class;
            $commandName = Str::replace(['filament:', 'filament-'], [static::$name . ':', static::$name . '-'], $command->getName());
            $command->setName($commandName);
            $command->setCode(function ($input, $output) use ($command) {
                config(['filament' => config('filament-blog')]);
                $command->handle($input, $output);
            });

            $commands[] = $command;
        }

        $this->commands($commands);
    }
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions