Last active
August 29, 2015 14:02
-
-
Save antonioribeiro/fa4db2b790073332abd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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