Created
October 27, 2015 19:15
-
-
Save jlem/0a3e8a19a18bedb60a49 to your computer and use it in GitHub Desktop.
Medium Laravel Story - Member.php
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
<?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