1. Go to this page and download the library: Download sereny/postgrest library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sereny / postgrest example snippets
User::where('age', '>', 18)->orderBy('name')->limit(10)->get();
// GET /users?age=gt.18&order=name.asc&limit=10
use Sereny\PostgREST\Eloquent\Model;
class User extends Model
{
protected $connection = 'postgrest';
public function roles()
{
return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id');
}
}
$roles = User::find(1)->roles; // lazy
User::with('roles')->get(); // eager, one embedded request
$roles = User::find(1)->roles()->withPivot('active')->get();
$user->roles()->attach($roleId); // writes to the pivot table
$user->roles()->detach($roleId);
use Sereny\PostgREST\Eloquent\Model;
class Country extends Model
{
protected $connection = 'postgrest';
public function posts()
{
return $this->hasManyThrough(Post::class, User::class);
}
}
Country::find(1)->posts; // GET /countries?select=*,users(country_id,posts(*))
Country::with('posts')->get(); // eager, one nested embedded request