Created
September 18, 2012 23:21
-
-
Save mailopl/3746684 to your computer and use it in GitHub Desktop.
In the framework jungle: Laravel Basic Model
This file contains 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
class User extends Eloquent { | |
public $rules = array( | |
'email' => 'required|email|unique:users', | |
'password' => 'between:8,50' | |
); | |
public function posts() | |
{ | |
return $this->has_many('Post'); | |
} | |
} | |
class Post extends Eloquent { | |
public $rules = array( | |
'name' => 'required|between:3,45', | |
'content' => 'required|between:8,2000' | |
); | |
public function tags() | |
{ | |
return $this->has_many_and_belongs_to('Tag'); | |
} | |
public function user() | |
{ | |
return $this->belongs_to('User'); | |
} | |
} | |
class Tag extends Eloquent { | |
public function posts() | |
{ | |
return $this->has_many_and_belongs_to('Post'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment