Skip to content

Instantly share code, notes, and snippets.

@jlem
Created October 27, 2015 19:15
Show Gist options
  • Save jlem/0a3e8a19a18bedb60a49 to your computer and use it in GitHub Desktop.
Save jlem/0a3e8a19a18bedb60a49 to your computer and use it in GitHub Desktop.
Medium Laravel Story - Member.php
<?php
class Member extends Model implements MemberInterface
{
const ATTR_DISPLAY_NAME = ‘display_name’;
const ATTR_LOGIN_NAME = ‘login_name’;
const ATTR_POST_COUNT = ‘posts’;
protected $fillable = [
self::ATTR_LOGIN_NAME,
self::ATTR_DISPLAY_NAME
];
public function getID()
{
return $this->getKey()
}
public function getLoginName()
{
return $this->{self::ATTR_LOGIN_NAME};
}
public function getDisplayName()
{
return $this->{self::ATTR_DISPLAY_NAME};
}
public function getPostCount()
{
return $this->{self::ATTR_POST_COUNT};
}
public function incrementPostCount()
{
$this->{self::ATTR_POST_COUNT}++;
}
public function decrementPostCount()
{
if ($this->getPostCount() > 0) {
$this->{self::ATTR_POST_COUNT}--;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment