Eloquent.Post.find(1).then(post => console.log(post));  
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
Post {id: 1, title: "My first post", body: "Hello, this is a post!", visible: true, created_at: Sat Jan 23 2016 00:42:26 GMT+0000 (GMT)…}


Bring your Eloquent ORM to the browser

Get Started

If you've already defined your models as part of a Laravel application, don't start from scratch with your javascript! EloquentJs takes your existing configuration and provides client-side access to your data with the same Eloquent API you already know.

Define an Eloquent model

class Post extends Model
  public function comments()
    return $this->hasMany(Comment::class);

Build your eloquent.js

$ php artisan eloquentjs:generate

| Model    | Endpoint  |
| App\Post | api/posts |

written to: public/eloquent.js

Use eloquent in javascript

Eloquent.Post.find(1).then(post => {

  console.log('fetched #' + post.id);
  post.update({title: 'My new title'});
  post.load('comments').then(/* ... */);


Why use EloquentJs?

minimal learning curve - as far as practical, uses the same API as Laravel's Eloquent
runs in any ES5 and Fetch capable browser*
client library is just 17KB (3.8KB gzipped) and no dependencies
written in ES2015 (babelified for production)
with tests and docs Coverage Status API docs
* fetch polyfill can be used

parsnick/eloquentjs the PHP package

This is the server-side package which interprets incoming queries, checks for authorisation, and generates the relevant response. It comes bundled with the latest eloquentjs build so it's all you usually need.


eloquentjs the node package

For advanced usage, the complete source of the client-side half of EloquentJs is available here. It provides the Eloquent API in javascript and can be imported into your own build process using browserify, webpack, or similar.