PHP code example of wwwision / likes

1. Go to this page and download the library: Download wwwision/likes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wwwision / likes example snippets


final class FavoriteCoffeeBeans {
  
    private LikeService $likeService;

    private User $authenticatedUser;

    public function __construct(LikeService $likeService, User $authenticatedUser) {
        $this->likeService = $likeService;
        $this->authenticatedUser = $authenticatedUser;
    }

    public function addCoffeeBean(CoffeeBean $coffeeBean): void
    {
        $this->likeService->addLike('CoffeeBeans', (string)$this->authenticatedUser->getId(), (string)$coffeeBean->getId());
    }

    public function removeCoffeeBean(CoffeeBean $coffeeBean): void
    {
        $this->likeService->revokeLike('CoffeeBeans', (string)$this->authenticatedUser->getId(), (string)$coffeeBean->getId());
    }

    public function contains(CoffeeBean $coffeeBean): bool
    {
        return $this->likeService->likeExists('CoffeeBeans', (string)$this->authenticatedUser->getId(), (string)$coffeeBean->getId());
    }
}