Skip to content

Instantly share code, notes, and snippets.

@alexjustesen
Created July 9, 2025 14:44
Show Gist options
  • Select an option

  • Save alexjustesen/f5842058fb03b306f873765207478562 to your computer and use it in GitHub Desktop.

Select an option

Save alexjustesen/f5842058fb03b306f873765207478562 to your computer and use it in GitHub Desktop.
Install Postgres extensions as a Laravel command.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class InstallPostgresExtension extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:install-postgres-extension
{name* : The name of the Postgres extension}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install Postgres extensions';
/**
* Execute the console command.
*/
public function handle(): void
{
foreach ($this->argument('name') as $extension) {
$this->line("⏳ Installing '{$extension}' extension...");
try {
DB::statement("CREATE EXTENSION IF NOT EXISTS {$extension};");
} catch (\Throwable $th) {
$this->error("Failed to install extension '{$extension}': {$th->getMessage()}");
return;
}
$this->line("✅ Extension '{$extension}' installed successfully.");
$this->newLine();
}
$this->info('Postgres extensions installed successfully.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment