reinvanoyen/oak-wishlist

该包最新版本(1.0.1)没有可用的许可信息。

Oak 的愿望清单

1.0.1 2019-09-19 12:55 UTC

This package is auto-updated.

Last update: 2024-09-19 23:59:19 UTC


README

为DRY应用程序提供简单的愿望清单实现

安装

composer require reinvanoyen/oak-wishlist

示例用法

准备你的项目
<?php

use Tnt\Wishlist\Contracts\WishlistItemInterface;

class Product implements WishlistItemInterface
{
    public static function getByWishlistId(int $id): ?WishlistItemInterface
    {
        // get the product by id
    }
    
    public function getWishlistId(): int
    {
        return 1;
    }
    
    public function serialize(): array
    {
        return [
            'id' => $this->getWishListId(),
            'title' => 'Your wishlistable product #1',
        ];
    }
}
使用外观(facade)
<?php

use Tnt\Wishlist\Facade\Wishlist;

$product = new Product();

// Add an item
Wishlist::add($product);

// Remove an item
Wishlist::remove($product);

// Check if an item is wishlisted
if (Wishlist::has($product)) {
    echo 'Yes, it is a wishlisted item!';
}

// Retrieve all wishlisted items
Wishlist::getItems();

// Clear all items from the wishlist
Wishlist::clear();