jijunair/laravel-referral
Composer 安装命令:
composer require jijunair/laravel-referral
包简介
Laravel package for a referral system
关键字:
README 文档
README
The Laravel Referral package (jijunair/laravel-referral) is a powerful and easy-to-use package for adding referral system functionality to your Laravel applications. With this package, you can effortlessly generate referral codes, track user referrals, and reward users based on their referrals.
Key Features
✅ Generate unique referral codes for users
✅ Track referrals and associate them with users
✅ Retrieve referrers and their referred users
✅ Customizable referral code length, cookie tracking, and redirection
✅ Simple trait-based integration with your User model
Installation
You can install the package via Composer by running the following command:
composer require jijunair/laravel-referral
Configuration
The package provides a configuration file that allows you to customize its behavior. You should publish the migration and the config/referral.php config file with:
php artisan vendor:publish --provider="Jijunair\LaravelReferral\Providers\ReferralServiceProvider"
After publishing, you can find the configuration file at config/referral.php.
| Configuration Key | Description |
|---|---|
cookie_name |
The name of the cookie that tracks referrals. |
cookie_expiry |
How long the referral cookie will be valid. (Default: 1 year) |
route_prefix |
The prefix used for referral links. |
ref_code_prefix |
The prefix added to the unique referral code for each user. |
redirect_route |
The page where users will go after clicking on a referral link. |
user_model |
The model class for the user. |
referral_length |
The length of the referral code for each user. (Default: 8 characters) |
These configuration options help customize the behavior of the referral system in your Laravel application. Feel free to adjust these values according to your preferences and requirements!
Migration
After the config and migration have been published and configured, you can create the tables for this package by running:
php artisan migrate
Add Trait
Add the necessary trait to your User model:
use Jijunair\LaravelReferral\Traits\Referrable; class User extends Model { use Referrable; }
Usage
Generate Referral Accounts for Existing Users
To generate referral accounts for existing users, you can visit the following URL:
http://localhost:8000/generate-ref-accounts
This will generate referral codes for all existing users in your application.
Get the Referrer of a User
To get the referrer of a user, you can use the following code:
use Illuminate\Support\Facades\Auth; $user = Auth::user(); $referrer = $user->referralAccount->referrer;
This retrieves the referrer associated with the user.
Get Referrer by Referral Code
To get the referrer by referral code, you can use the following code:
use Jijunair\LaravelReferral\Models\Referral; use Illuminate\Support\Facades\Cookie; $referralCode = Cookie::get(config('referral.cookie_name')); $referrer = Referral::userByReferralCode($referralCode);
This retrieves the referrer based on the referral code stored in the cookie.
Check if a User has a Referral Account
To check if a user has a referral account, you can use the following code:
$user->hasReferralAccount();
This returns true if the user has a referral account, and false otherwise.
Create a Referral Account for a User
To create a referral account for a user, you can use the following code:
$user->createReferralAccount($referrer->id);
This associates the user with the provided referrer by creating a referral account.
Get All Referrals of a User
To get all referrals under a user, you can use the following code:
$referrals = $user->referrals;
This retrieves all the referrals associated with the user.
Get the Referral Link of a User
To get the referral link of a user, you can use the following code:
$referralLink = $user->getReferralLink();
This returns the referral link associated with the user.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Thank you for considering contributing to the Laravel Referral Package! If you have any suggestions, bug reports, or pull requests, please feel free to open an issue or submit a pull request on the GitHub repository.
License
The Laravel Referral Package is open-source software licensed under the MIT license.
jijunair/laravel-referral 适用场景与选型建议
jijunair/laravel-referral 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.2k 次下载、GitHub Stars 达 93, 最近一次更新时间为 2023 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「laravel」 「referral」 「affiliate」 「referral-system」 「laravel-referral」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jijunair/laravel-referral 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jijunair/laravel-referral 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jijunair/laravel-referral 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This client allows you to implement referral programs using the Genius Referrals RESTful API.
BayRewards PHP SDK for Laravel Framework - A comprehensive rewards platform integration for e-commerce stores.
Spam Blocker is a package that allows you to block referral spammers
Simple ASCII output of array data
Laravel package for a referral system
统计信息
- 总下载量: 34.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 93
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-13
