Download the PHP package tlsgroup/laravel-referral without Composer
On this page you can find all versions of the php package tlsgroup/laravel-referral. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tlsgroup/laravel-referral
More information about tlsgroup/laravel-referral
Files in tlsgroup/laravel-referral
Package laravel-referral
Short Description Laravel package for a referral system
License MIT
Homepage https://github.com/TLSGROUP/laravel-referral
Informations about the package laravel-referral
The "TLSGROUP/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
- Configuration
- Migration
- Add Trait
- Usage
- Generate Referral Accounts for Existing Users
- Get the Referrer of a User
- Get Referrer by Referral Code
- Check if a User has a Referral Account
- Create a Referral Account for a User
- Get All Referrals of a User
- Get the Referral Link of a User
- Changelog
- Contribution
- License
Installation
You can install the package via Composer by running the following command:
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:
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:
Add Trait
Add the necessary trait to your User model:
Usage
Generate Referral Accounts for Existing Users
To generate referral accounts for existing users, you can visit the following URL:
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:
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:
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:
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:
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:
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:
This returns the referral link associated with the user.
License
The Laravel Referral Package is open-source software licensed under the MIT license.
All versions of laravel-referral with dependencies
illuminate/database Version ^8.0|^9.0|^10.0|^11.0
illuminate/auth Version ^8.0|^9.0|^10.0|^11.0