Created
October 27, 2015 19:38
-
-
Save jlem/a32c23e037126ba6e10c to your computer and use it in GitHub Desktop.
Revisions
-
Jon LeMaitre created this gist
Oct 27, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ <?php DemonstrationController { public function createPost() { // validate request, create the post, and... $member = Auth::user()->member(); $member->incrementPostCount(); } public function deletePost() { // validate request, delete the post, and... $member = Auth::user()->member(); $member->decrementPostCount(); } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ <?php class Member extends Model implements MemberInterface { //... public function incrementPostCount() { $this->{self::ATTR_POST_COUNT}++; $this->save(); } public function decrementPostCount() { if ($this->getPostCount() > 0) { $this->{self::ATTR_POST_COUNT}--; $this->save(); } } // ... }