E
E
Eugene2022-03-31 17:39:35
Laravel
Eugene, 2022-03-31 17:39:35

How to create int[] column using laravel ORM?

I'm digging into the legacy project. Laravel version 5. Postgres 14 version. int[] has been supporting it for a long time.

In migration I'm trying to create a column in pure SQL

DB::statement('ALTER TABLE '.$needle_table.' ADD COLUMN parents int[]');

Artisan gives an interesting error.
In AbstractPlatform.php line 454:

  Unknown database type _int4 requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it.

Already all Google has been vacuumed and found nothing except some kind of ala decision to do
DB::connection()->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping()

It's weird in general. How can I create an int[] in Laravel 5?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2022-04-01
@evgen9586

\DB::connection()->setSchemaGrammar(new class extends PostgresGrammar {
            protected function typeInt_array(\Illuminate\Support\Fluent $column)
            {
                return 'int[]';
            }
        });
//В миграции потом
$table->addColumn('int_array', 'parents')->nullable();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question