alpetg/wishlist
Composer 安装命令:
composer require alpetg/wishlist
包简介
Make Models wishlistable
README 文档
README
Make Eloquent Model models wishlistable
Installation
You can install the package via composer:
composer require alpetg/wishlist
Migrations
You can publish and run the migrations with:
php artisan vendor:publish --tag="wishlist-migrations"
php artisan migrate
Configuration
You can publish the config file with:
php artisan vendor:publish --tag="wishlist-config"
Usage
Prepare Models
Add Wishlist on User Model
use AlpetG\Wishlist\Traits\Wishlist; class User extends Authenticatable { use Wishlist; <...> }
Add Wishlistable on every model u want have wishlist on
use AlpetG\Wishlist\Traits\Wishlistable; class Products extends Model { use Wishlistable; <...> }
API
$user = User::find(1); $product = Product::find(3); $user->wish($product); $user->unwish($product); $user->toggleWishlist($product); //Or Dircet from product $product->wish() $product->unwish() $product->toggleWishlist()
Aggregations
// All $user->->wishlist()->count(); //or $user->wishlistCount(); // with type $user->wishlist()->withType(Product::class)->count();
List with *_count attribute:
$user = User::withCount('wishlist')->get();
foreach ($user_count as $user) {
echo $user->wishlist_count;
}
Attach the Wishlist status to wishlistable collection
You can use Wishlist::attachWishlistStatus(Collection $wishlists) to attach the user Wishlist status, it will set is_wishlisted attribute to each model of $wishlists:
For model
$user1 = User::find(1); $user->attachWishlistStatus($user1); // result [ "id" => 1 "name" => "user1" "created_at" => "2022-09-24T23:06:47.000000Z" "updated_at" => "2022-09-24T23:06:47.000000Z" "is_wishlisted" => true ]
For Collection | Paginator | LengthAwarePaginator | array:
$user = auth()->user(); $products = Product::oldest('id')->get(); $products = $user->attachWishlistStatus($products); $products = $products->toArray(); // result [ [ "id" => 1 "title" => "product 1" "created_at" => "2022-09-24T23:06:47.000000Z" "updated_at" => "2022-09-24T23:06:47.000000Z" "is_wishlisted" => true ], [ "id" => 2 "title" => "product 2" "created_at" => "2022-09-24T23:06:47.000000Z" "updated_at" => "2022-09-24T23:06:47.000000Z" "is_wishlisted" => true ], [ "id" => 3 "title" => "product 3" "created_at" => "2022-09-24T23:06:47.000000Z" "updated_at" => "2022-09-24T23:06:47.000000Z" "is_wishlisted" => false ], ]
For pagination
$products = Product::paginate(10); $user->attachWishlistStatus($products);
Easy Way to Use
$products = Product::paginate(10); $user->getMyWish($products);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
alpetg/wishlist 适用场景与选型建议
alpetg/wishlist 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 4, 最近一次更新时间为 2022 年 09 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「laravel」 「wishlist」 「laravel-package」 「AlpetG」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alpetg/wishlist 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alpetg/wishlist 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alpetg/wishlist 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Manage your users' wishes in a Laravel app
A CakePHP plugin for managing user favorites, bookmarks and wishlists
wishlist for laravel 5.*.*
Simple ASCII output of array data
Wishlist bundle for Sylius e-commerce platform.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-24