Created
July 9, 2025 14:44
-
-
Save alexjustesen/f5842058fb03b306f873765207478562 to your computer and use it in GitHub Desktop.
Install Postgres extensions as a Laravel command.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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