Laravel PostgreSQL Enhanced
Adds PostgreSQL-specific migration, query builder, and Eloquent features Laravel leaves out
Repository Health
Technical Analysis
Laravel PostgreSQL Enhanced extends Laravel’s schema builder, query builder, and Eloquent with the PostgreSQL-specific functionality Laravel omits to stay database-agnostic. It covers migrations (functions, triggers, views, materialized views, zero-downtime index creation, nulls-not-distinct indexes, domain types, table storage parameters) and column types (arrays, ranges, bit strings, case-insensitive text, full text search, hstore, IP networks, label trees, vectors, XML).
On the query side it adds CTEs, lateral subquery joins, RETURNING clause support, cursor-based lazy iteration, and native full text search query helpers, plus Eloquent casts and refresh-on-save behavior tuned to PostgreSQL types. It is aimed at teams who have committed to PostgreSQL and want to use its advanced features directly from Laravel instead of dropping to raw SQL.
What You Get
- Migration support for PostgreSQL functions, triggers, views, materialized views, and zero-downtime concurrent index creation
- Specialized index types: nulls-not-distinct, partial, functional, fulltext, and temporal indexes with storage parameters
- PostgreSQL-native column types: arrays, ranges, bit strings, case-insensitive text, hstore, IP networks, label trees, and vectors
- Query builder additions for common table expressions (CTEs), lateral subquery joins, and
RETURNINGclause data - Cursor-based lazy result iteration for memory-efficient large query processing
- Eloquent casts and refresh-on-save behavior tailored to PostgreSQL-specific column types
Common Use Cases
- Adding full text search directly to a Laravel app’s PostgreSQL columns without a separate search service
- Writing recursive or multi-step queries with CTEs instead of chaining multiple query builder calls
- Creating indexes concurrently in production migrations without locking the table
- Storing structured data natively as PostgreSQL arrays, ranges, or hstore instead of serializing to JSON
- Using lateral joins to correlate a subquery per row, such as fetching each user’s N most recent orders
Under The Hood
Architecture The package registers PostgresqlEnhancedServiceProvider to swap in a custom PostgresEnhancedConnection and matching schema grammar, then layers PostgreSQL-specific builder methods across src/Schema/ (migrations, indexes, column types), src/Query/ (CTEs, lateral joins, cursors), and src/Eloquent/ (casts, refresh-on-save), with src/Backports/ providing shims for features from newer Laravel versions on older ones and src/Expressions/ wrapping raw SQL fragments as typed query expressions. Tech Stack Pure PHP 8.0+ built on Laravel’s illuminate/database (versions 6 through 13 supported simultaneously) with doctrine/dbal for schema introspection and spatie/regex for parsing; dev tooling includes PHPStan (levels 1-2), PHP-CS-Fixer, and Orchestra Testbench for package testing. Code Quality 40 test files exercise the schema, query, and Eloquent layers, with the broad Laravel version matrix (6.0 through 13.0) in composer.json signaling deliberate backward-compatibility testing; the Backports directory shows an explicit strategy for handling Laravel API drift across major versions rather than requiring the latest Laravel release. API Design Every addition is designed as a fluent extension of Laravel’s existing schema/query builder syntax (e.g. $table->fulltext(), ->withCte(), ->lateralJoin()), so developers already fluent in Laravel migrations and query building pick up the PostgreSQL-specific methods with almost no new syntax to learn.