Skip to content

Instantly share code, notes, and snippets.

@mailopl
Created September 18, 2012 23:21
Show Gist options
  • Save mailopl/3746684 to your computer and use it in GitHub Desktop.
Save mailopl/3746684 to your computer and use it in GitHub Desktop.
In the framework jungle: Laravel Basic Model
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