sapere/laravel-referral 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sapere/laravel-referral

Composer 安装命令:

composer require sapere/laravel-referral

包简介

Laravel package for a referral system.

README 文档

README

Latest Version on Packagist Total Downloads License

The "sapere/laravel-referral" package is a custom Laravel package that provides referral code functionality for your Laravel applications. It allows you to generate referral codes, associate them with users, retrieve users based on their referral codes and all other related features.

Installation

You can install the package via Composer by running the following command:

composer require sapere/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="sapere\LaravelReferral\Providers\ReferralServiceProvider"

After publishing, you can find the configuration file at config/referral.php. This file allows you to configure the cookie name and other package-specific settings.

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 sapere\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 sapere\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.

sapere/laravel-referral 适用场景与选型建议

sapere/laravel-referral 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sapere/laravel-referral 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sapere/laravel-referral 我们能提供哪些服务?
定制开发 / 二次开发

基于 sapere/laravel-referral 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-06