PHPackages                             limanweb/pg-ext - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. limanweb/pg-ext

ActivePackage[Database &amp; ORM](/categories/database)

limanweb/pg-ext
===============

Laravel extensions to work with Postgresql table native field-types

v1.2.2(2y ago)26.6k↓65.8%MITPHPPHP ^7.2|^8.0

Since Dec 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/limanweb/pg-ext)[ Packagist](https://packagist.org/packages/limanweb/pg-ext)[ RSS](/packages/limanweb-pg-ext/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)DependenciesVersions (6)Used By (0)

pg-ext
======

[](#pg-ext)

Extending the laravel to work with PostgreSQL tables

### Provides

[](#provides)

- additional casting types for the some native PostgreSQL types
- additional many-to-many relations with using of specific PostgreSQL array-type fields

### Anounced (in developing)

[](#anounced-in-developing)

- extension of BluePrint to operate PostgreSQL array fields and GIN-indexes

Installation
------------

[](#installation)

Run:

```
composer require "limanweb/pg-ext"
```

Package contents
----------------

[](#package-contents)

- **Models**\\
    - **Concerns**\\
        - **PgTypeCastable** - cast some PostgreSQL native types for model
        - **HasArrayRelationships** - additional relations for model
    - **Model** - The abstract model that used PgTypeCastable &amp; HasArrayRelationships traits
- **Relations**\\
    - **ArrayRelations** - base abstract class for array-field relations
    - **HasManyInArray** - HasManyInArray relation class
    - **BelongsToManyArrays** - BelongsToManyArrays relation class
- **Support**\\
    - **PgHelper** - PostgreSQL native type convertion helper

Using extended casting
----------------------

[](#using-extended-casting)

Use trait Limanweb\\PgExt\\Models\\Concerns\\PgTypeCastable in your model to cast some native PostgreSQL types

1. Add trait `Limanweb\PgExt\Models\Concerns\PgTypeCastable` into your model

```
use Illuminate\Database\Eloquent\Model;

class YourModel extends Model
{
	use Limanweb\PgExt\Models\Concerns\PgTypeCastable;

	// Your model implementation
}
```

or inherite your model from `Limanweb\PgExt\Models\Model` to use extended casting by default.

```
use Limanweb\PgExt\Models\Model;

class YourModel extends Model
{
	// Your model implementation
}
```

2. Describe your table array fields in $casts property with 'pg\_array'

```
protected $casts = [
	'your_array_field' => 'pg_array',
];
```

Available cast types:

- **pg\_array** - use for one dimension array fields ("text\[\]", "varchar\[\]", "int\[\]" and other)

Now you can operate with array-attributes of model like with PHP-array.

Using extended relations
------------------------

[](#using-extended-relations)

Add trait `Limanweb\PgExt\Models\Concerns\HasArrayRelationships` into your model

```
use Illuminate\Database\Eloquent\Model;

class YourModel extends Model
{
	use Limanweb\PgExt\Models\Concerns\PgTypeCastable;
	use Limanweb\PgExt\Models\Concerns\HasArrayRelationships;

	// Your model implementation
}
```

or inherite your model from `Limanweb\PgExt\Models\Model` to use extended casting and relationships by default.

### What many-to-many relation trough array-field

[](#what-many-to-many-relation-trough-array-field)

For example, you have two tables: posts and tags. Every post can have many tags, and every tag can be associated with many posts. You can add a column 'tag\_ids' of native PostgreSQL type 'INTEGER\[\]' (array of integer) into 'posts' table. Now, you can use this field to specify ID-s of tags associated with post.

Notes: Don't forget to create GIN-index on 'tag\_ids' field.

Using the hasManyInArray and the belongsToManyArrays relationships allows you to access related models. See examples below.

### hasManyInArray relation

[](#hasmanyinarray-relation)

```
use Limanweb\PgExt\Models\Model;

class Post extends Model {

	protected $casts = [
		'name' => 'string',
		'tag_ids' => 'pg_array', 	// this is array of integer PostgreSQL field
						// in SQL is "country_is INTEGER[],"
	];

	// Your model implementation

	/**
	 * @return Limanweb\PgExt\Relations\HasManyInArray
	 */
	public function tags() {
		return $this->hasManyInArray(Tag::class, 'tag_ids', 'id');
	}
}
```

### belongsToManyArrays relation

[](#belongstomanyarrays-relation)

```
use Limanweb\PgExt\Models\Model;

class Tag extends Model {

	protected $casts = [
		'name' => 'string',
	];

	// Your model implementation

	/**
	 * @return Limanweb\PgExt\Relations\BelongsToManyArrays
	 */
	public function posts() {
		return $this->belongsToManyArrays(Post::class, 'tag_ids', 'id');
	}
}
```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~497 days

Total

5

Last Release

766d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.2.0

v1.2.2PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/be8a9bfa93eb4d34ba70ea4bfd941a0d346b67f3030248cb4b443168084eb7a1?d=identicon)[limanweb](/maintainers/limanweb)

---

Top Contributors

[![limanweb](https://avatars.githubusercontent.com/u/17918827?v=4)](https://github.com/limanweb "limanweb (10 commits)")

---

Tags

laravelpostgresql

### Embed Badge

![Health badge](/badges/limanweb-pg-ext/health.svg)

```
[![Health](https://phpackages.com/badges/limanweb-pg-ext/health.svg)](https://phpackages.com/packages/limanweb-pg-ext)
```

###  Alternatives

[pmatseykanets/laravel-scout-postgres

PostgreSQL Full Text Search Driver for Laravel Scout

166219.3k2](/packages/pmatseykanets-laravel-scout-postgres)[umbrellio/laravel-ltree

Extension LTree (Postgres) for Laravel

34120.1k](/packages/umbrellio-laravel-ltree)[moharrum/laravel-adminer

Adminer database management tool for your Laravel application.

451.0k](/packages/moharrum-laravel-adminer)[ramadan/easy-model

A Laravel package for enjoyably managing database queries.

111.6k](/packages/ramadan-easy-model)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
