Skip to content

Commit

Permalink
fix(laravel): installation command, fix config overwrites (#6649)
Browse files Browse the repository at this point in the history
added the installation command, but as a bug fix since configs are currently getting overwritten.

Closes: #6645
  • Loading branch information
toitzi authored Sep 21, 2024
1 parent f2f06d1 commit 88bd8c3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,10 @@ function (Application $app) {
if ($this->app['config']->get('api-platform.graphql.enabled')) {
$this->registerGraphQl($this->app);
}

if ($this->app->runningInConsole()) {
$this->commands([Console\InstallCommand::class]);
}
}

private function registerGraphQl(Application $app): void
Expand Down Expand Up @@ -1210,11 +1214,11 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/config/api-platform.php' => $this->app->configPath('api-platform.php'),
], 'laravel-assets');
], 'api-platform-config');

$this->publishes([
__DIR__.'/public' => $this->app->publicPath('vendor/api-platform'),
], 'laravel-assets');
], ['api-platform-assets', 'public']);
}

$this->loadViewsFrom(__DIR__.'/resources/views', 'api-platform');
Expand Down
45 changes: 45 additions & 0 deletions src/Laravel/Console/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Laravel\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'api-platform:install')]
class InstallCommand extends Command
{
/**
* @var string
*/
protected $signature = 'api-platform:install';

/**
* @var string
*/
protected $description = 'Install all of the API Platform resources';

/**
* Execute the console command.
*/
public function handle(): void
{
$this->comment('Publishing API Platform Assets...');
$this->callSilent('vendor:publish', ['--tag' => 'api-platform-assets']);

$this->comment('Publishing API Platform Configuration...');
$this->callSilent('vendor:publish', ['--tag' => 'api-platform-config']);

$this->info('API Platform installed successfully.');
}
}

0 comments on commit 88bd8c3

Please sign in to comment.