Skip to content

Instantly share code, notes, and snippets.

@mtigdemir
Forked from jlem/Member.php
Created November 28, 2017 11:03
Show Gist options
  • Save mtigdemir/11817f872837ba83dee3a2e4848cd339 to your computer and use it in GitHub Desktop.
Save mtigdemir/11817f872837ba83dee3a2e4848cd339 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