izqut/membership
Composer 安装命令:
composer require izqut/membership
包简介
Laravel ئۈچۈن ئاددىي ۋە ئۈنۈملۈك ئالىي ئەزالىق باشقۇرۇش بولىقى
README 文档
README
A simple and powerful membership management package for Laravel.
Features
- ✅ Simple and easy-to-use API
- ✅ Check VIP membership with
$user->isVip() - ✅ Support for multiple membership plans
- ✅ Lifetime (perpetual) membership support
- ✅ Time-based membership management
- ✅ Blade directives (@vip, @membership)
- ✅ Helper functions
- ✅ Flexible user model configuration
- ✅ Compatible with PHP 7.3+ and Laravel 8-11
Installation
composer require izqut/membership
Setup
1. Run Migrations
php artisan migrate
2. Publish Config (Optional)
php artisan vendor:publish --tag=membership-config
3. Add Trait to User Model
use Izqut\Membership\Traits\HasMembership;
class User extends Authenticatable
{
use HasMembership;
// ...
}
4. Custom User Model (Optional)
If your user model is not named User (e.g., UserAccount, Member), configure it in the config file:
// config/membership.php
'user_model' => App\Models\UserAccount::class,
Or in .env:
MEMBERSHIP_USER_MODEL=App\Models\UserAccount
Usage
Creating Membership Plans
use Izqut\Membership\Models\Membership;
// Create VIP membership (slug='vip' is automatically recognized as VIP)
Membership::create([
'name' => 'VIP Membership',
'slug' => 'vip',
'price' => 99.99,
'duration_days' => 30, // 30 days
'is_active' => true,
]);
// Create Premium membership
Membership::create([
'name' => 'Premium Membership',
'slug' => 'premium',
'price' => 49.99,
'duration_days' => 30,
'is_active' => true,
]);
// Create Lifetime membership
Membership::create([
'name' => 'Lifetime Membership',
'slug' => 'lifetime',
'price' => 299.99,
'duration_days' => null, // null = lifetime
'is_active' => true,
]);
Subscribing Users
$user = User::find(1);
$plan = Membership::where('slug', 'vip')->first();
// Subscribe to membership
$user->subscribe($plan);
// Or by ID
$user->subscribe(1);
Checking VIP Status
// In controller
if ($user->isVip()) {
// VIP features
}
// Or using helper function
if (is_vip()) {
// Current user is VIP
}
Checking Membership
// Has active membership?
if ($user->hasMembership()) {
// User has membership
}
// Has specific membership plan?
if ($user->hasMembershipPlan('vip')) {
// User has VIP membership
}
// Get current membership plan
$plan = $user->currentMembershipPlan();
// Get remaining days
$daysLeft = $user->membershipDaysRemaining();
Using in Blade Templates
{{-- Show to VIP members only --}}
@vip
<div class="vip-content">
VIP Exclusive Content
</div>
@endvip
{{-- Show to members --}}
@membership
<div class="member-content">
Members Only Content
</div>
@else
<div class="non-member">
Get membership now!
</div>
@endmembership
{{-- Show to specific membership plan --}}
@membershipPlan('premium')
<div class="premium-content">
Premium Content
</div>
@endmembershipPlan
Helper Functions
// Get current user's membership
$membership = membership();
// Check if VIP
if (is_vip()) {
// VIP user
}
// Check if has membership
if (has_membership()) {
// Has membership
}
// Check specific membership
if (has_membership('vip')) {
// Has VIP membership
}
// Get all active membership plans
$plans = membership_plans();
Canceling Membership
$user->cancelMembership();
Advanced Usage
// Membership details
$membership = $user->membership;
if ($membership) {
// Is active?
$isActive = $membership->isActive();
// Is expired?
$isExpired = $membership->isExpired();
// Days remaining
$daysLeft = $membership->daysRemaining();
// Membership plan
$plan = $membership->membership;
// Activate/Deactivate
$membership->activate();
$membership->deactivate();
}
Eloquent Scopes
use Izqut\Membership\Models\UserMembership;
// Active memberships
$activeMemberships = UserMembership::active()->get();
// Expired memberships
$expiredMemberships = UserMembership::expired()->get();
// Expiring soon (within 7 days)
$expiringSoon = UserMembership::expiringSoon(7)->get();
Database Structure
memberships table
id- Primary keyname- Membership nameslug- URL-friendly identifier (slug='vip' is recognized as VIP)description- Descriptionprice- Priceduration_days- Duration in days (null = lifetime)is_active- Is active?features- Features (JSON)sort_order- Sort order
user_memberships table
id- Primary keyuser_id- User IDmembership_id- Membership plan IDstarts_at- Start dateexpires_at- Expiration dateis_active- Is active?
Configuration
You can customize the following settings in config/membership.php:
return [
'currency' => 'USD',
'default_duration' => 30,
'vip_slug' => 'vip',
'user_model' => 'App\\Models\\User', // User model class
'grace_period_days' => 0,
'auto_deactivate_expired' => true,
];
Configuration Options
- currency: Currency code (USD, EUR, etc.)
- default_duration: Default membership duration in days
- vip_slug: VIP membership slug identifier (default: 'vip')
- user_model: Fully qualified user model class name
- grace_period_days: Grace period after expiration
- auto_deactivate_expired: Auto-deactivate expired memberships
Examples
Simple Example
// 1. Create membership plan (slug='vip' is automatically VIP)
$vipPlan = Membership::create([
'name' => 'VIP',
'slug' => 'vip',
'price' => 49.99,
'duration_days' => 30,
'is_active' => true,
]);
// 2. Subscribe user
$user = User::find(1);
$user->subscribe($vipPlan);
// 3. Check status
if ($user->isVip()) {
echo "You are a VIP member!";
}
Blade Usage Example
<div class="user-dashboard">
@vip
<div class="alert alert-success">
Welcome VIP member! You have access to exclusive features.
</div>
<a href="/vip/downloads" class="btn btn-primary">
VIP Downloads
</a>
@else
<div class="alert alert-info">
<a href="/membership/plans">Become a VIP</a>
and unlock more features!
</div>
@endvip
</div>
Requirements
- PHP 7.3 or higher
- Laravel 8.0 or higher
License
MIT License
About
This package provides:
- Simple API - Easy-to-use methods like
$user->isVip() - Flexible - Easy to extend and customize
- Laravel Standard - Follows Laravel conventions
- Multiple Plans - Support for VIP, Premium, Basic, and custom membership types
- Composer Installation - Install with
composer require izqut/membership
izqut/membership 适用场景与选型建议
izqut/membership 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「subscription」 「laravel」 「membership」 「vip」 「user-membership」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 izqut/membership 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 izqut/membership 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 izqut/membership 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
pH7Builder. Social Dating Web App Site Builder
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Drupal Commerce API support for Membership module.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-20