Skip to content

Instantly share code, notes, and snippets.

@antonioribeiro
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save antonioribeiro/fa4db2b790073332abd8 to your computer and use it in GitHub Desktop.

Select an option

Save antonioribeiro/fa4db2b790073332abd8 to your computer and use it in GitHub Desktop.
<?php
$user = User::find(15); /// will find the user in Domino or Locally
class User Extends Eloquent {
protected $table = 'users';
public static function find($id)
{
$user = parent::find($id);
if (! $user)
{
$user = new static;
$user = $user->findOnDomino($id);
}
return $user;
}
public function findOnDomino($user_id)
{
// get data from domino
$this->data = $this->consumeFromDomino($user_id);
$new_user = new static;
$new_user->fillAttributes($this->data);
return $new_user->save();
}
private function fillAttributes($data)
{
foreach($data as $key => $value)
{
$this->setAttribute($key, $value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment