src/Likeable.php
public function like($userId=null)
	{
		if(is_null($userId)) {
			$userId = $this->loggedInUserId();
		}
		
		if($userId) {
			$like = $this->likes()
				->where('user_id', '=', $userId)
				->first();
	
			if($like) return;
	
			$like = new Like();
			$like->user_id = $userId;
			$this->likes()->save($like);
		}

		$this->incrementLikeCount();
	}
public function like($userId=null)
	{
		if(is_null($userId)) {
			$userId = $this->loggedInUserId();
		}
		
		if($userId) {
			$like = $this->likes()
				->where('user_id', '=', $userId)
				->first();
	
			if($like) return;
	
			$like = new Like();
			$like->user_id = $userId;
			$this->likes()->save($like);
		}

		$this->incrementLikeCount();
	}
public function like ( $ userId = null ) { if ( is_null ( $ userId ) ) { $ userId = $ this -> loggedInUserId ( ) ; } if ( $ userId ) { $ like = $ this -> likes ( ) -> where ( 'user_id' , '=' , $ userId ) -> first ( ) ; if ( $ like ) return ; $ like = new Like ( ) ; $ like -> user_id = $ userId ; $ this -> likes ( ) -> save ( $ like ) ; } $ this -> incrementLikeCount ( ) ; }
Add a like for this record by the given user.
@param $userId mixed - If null will use currently logged in user.
Add a like for this record by the given user .