Download the PHP package limanweb/pg-ext without Composer
On this page you can find all versions of the php package limanweb/pg-ext. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download limanweb/pg-ext
More information about limanweb/pg-ext
Files in limanweb/pg-ext
Package pg-ext
Short Description Laravel extensions to work with Postgresql table native field-types
License MIT
Informations about the package pg-ext
pg-ext
Extending the laravel to work with PostgreSQL tables
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)
- extension of BluePrint to operate PostgreSQL array fields and GIN-indexes
Installation
Run:
Package contents
- Models\
- Concerns\
- PgTypeCastable - cast some PostgreSQL native types for model
- HasArrayRelationships - additional relations for model
- Model - The abstract model that used PgTypeCastable & 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
Use trait Limanweb\PgExt\Models\Concerns\PgTypeCastable in your model to cast some native PostgreSQL types
- Add trait into your model
or inherite your model from to use extended casting by default.
- Describe your table array fields in $casts property with '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
Add trait into your model
or inherite your model from to use extended casting and relationships by default.
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.