Skip to content

Instantly share code, notes, and snippets.

@jlem
Created October 27, 2015 19:38
Show Gist options
  • Save jlem/a32c23e037126ba6e10c to your computer and use it in GitHub Desktop.
Save jlem/a32c23e037126ba6e10c to your computer and use it in GitHub Desktop.
Medium Laravel Article - leaky hybrid
<?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();
}
}
<?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();
}
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment