app/Models/Traits/Likeable.php
/**
     * Add a like for this record by the given user.
     *
     * @param $user mixed - If null will use currently logged in user.
     * @throws
     */
Add a like for this record by the given user.
@param $user mixed - If null will use currently logged in user.
@throws
Add a like for this record by the given user . @param $user mixed - If null will use currently logged in user . @throws
public function like($user = null)
    {
        if (null === $user) {
            $user = auth()->user();
        }
        $like = $this->likes()->where('user_id', '=', $user->id)->first();
        if ($like) {
            return;
        }
        $like = $this->likes()->create(['user_id' => $user->id]);
        if (! $this->mine()) {
            event(new NotificationEvent($like, $this->user));
        }
        $this->increment('likes_count');
    }
public function like ( $ user = null ) { if ( null === $ user ) { $ user = auth ( ) -> user ( ) ; } $ like = $ this -> likes ( ) -> where ( 'user_id' , '=' , $ user -> id ) -> first ( ) ; if ( $ like ) { return ; } $ like = $ this -> likes ( ) -> create ( [ 'user_id' => $ user -> id ] ) ; if ( ! $ this -> mine ( ) ) { event ( new NotificationEvent ( $ like , $ this -> user ) ) ; } $ this -> increment ( 'likes_count' ) ; }
Add a like for this record by the given user.
Add a like for this record by the given user .
// Send event if it's not our item