app/Reply.php
/**
     * Benefit of this approach, compare to increment in thread.php:
     * If use create('App\Reply'), it will automatically add replies_count to related thread.
     * @return void
     */
Benefit of this approach, compare to increment in thread.php:
If use create('App\Reply'), it will automatically add replies_count to related thread.
@return void
Benefit of this approach compare to increment in thread . php : If use create ( ' App \ Reply ' ) it will automatically add replies_count to related thread . @return void
protected static function boot()
    {
        parent::boot();
        static::created(function ($reply) {
            $reply->thread->increment('replies_count');
            $reply->owner->gainReputation('reply_posted');
        });
        static::deleting(function ($reply) {
            if ($reply->isBest()) {
                $reply->owner->loseReputation('best_reply_awarded');
            }
        });
        static::deleted(function ($reply) {
            $reply->thread->decrement('replies_count');
            $reply->owner->loseReputation('reply_posted');
        });
    }
protected static function boot ( ) { parent :: boot ( ) ; static :: created ( function ( $ reply ) { $ reply -> thread -> increment ( 'replies_count' ) ; $ reply -> owner -> gainReputation ( 'reply_posted' ) ; } ) ; static :: deleting ( function ( $ reply ) { if ( $ reply -> isBest ( ) ) { $ reply -> owner -> loseReputation ( 'best_reply_awarded' ) ; } } ) ; static :: deleted ( function ( $ reply ) { $ reply -> thread -> decrement ( 'replies_count' ) ; $ reply -> owner -> loseReputation ( 'reply_posted' ) ; } ) ; }
Benefit of this approach, compare to increment in thread.php:
 If use create('App\Reply'), it will automatically add replies_count to related thread.
Benefit of this approach compare to increment in thread . php : If use create ( ' App \ Reply ' ) it will automatically add replies_count to related thread .
// $reply->owner->increment('reputation', 2); // Reputation::gain($reply->owner, Reputation::REPLY_POSTED); // We can do it in the DB level. /* if ($reply->isBest()) {
                $reply->thread->update(['best_reply_id' => null]);
            } */ // Reputation::lose($reply->owner, Reputation::REPLY_POSTED);