haegemon/lara-array

Lara-array provide postgresql array datatype support at Eloquent ORM.

dev-master 2018-02-12 07:32 UTC

This package is not auto-updated.

Last update: 2020-09-17 19:37:12 UTC


README

Lara-array provide postgresql array datatype support at Eloquent ORM. Inspired by darrylkuhn/dialect.

Installation

Require this package in your composer.json file:

"haegemon/lara-array": "dev-master"

...then run composer update to download the package to your vendor directory.

Usage

The feature is exposed through a trait rewrite standart casting attributes to change array parse from json_decode to special parser for postgresql array. For example we could create a Photos model like this:

use Eloquent\LaraArray\LaraArray as LaraArray;

class Photo extends Eloquent
{
        use LaraArray;
    
        protected $casts = [
            'marks' => 'array',
        ];
}

And then this:

$marks = $photo->marks;

var_dump($marks); // array(2) { [0]=> string(1) "5" [1]=> string(1) "2" }