Looking to hire Laravel developers? Try LaraJobs

laravel-postgres maintained by asmiarowski

Description
Eloquent support for postgreSQL fields
Last update
2016/05/12 22:30 (dev-master)
License
Links
Downloads
38 173

Comments
comments powered by Disqus

laravel-postgres

Adds support for postgreSQL fields for Eloquent.

class ExampleModel extends Model { use PostgresArray; }

<p>Set up accessor and mutator for your array field like so:</p>

public function setArrayField(array $value) { $this->array_field = self::mutateToPgArray($value); } public function getArrayField() { return self::accessPgArray($this->array_field); }

<p>Query scopes available for builder:</p>
<p><b>wherePgArrayContains(string $column, mixed $value)</b>: Adds where query part, $column has all of the elements in $value. $value can be array, integer or string</p>
<p><b>wherePgArrayOverlap(string $column, mixed $value)</b>: Adds where query part, $column has any (at least one) of the elements in $value. $value can be array, integer or string</p>

<p>For example, let's say you have an array of strings as tags for restaurants. If you would want to find all restaurants that serve pizza or lasagne, you would build your query like so:</p>

$restaurants = Restaurant::wherePgArrayOverlap('tag', ['pizza', 'lasagne'])->get();

<p>Above example would return only thoes restaurants that have tags pizza <b>or</b> lasagne in their defined tags field. If you would want only restaurants that have all of the tags specified, you would use <b>wherePgArrayContains</b> instead.</p>