titonova / laravel-referral
A package for Laravel to register referrals with ease.
Fund package maintenance!
robindirksen.com
Requires
- php: ^7.2|^7.3|^7.4|^8.0
- illuminate/database: ^5.8|^6.0|^7.0|^8.0
- illuminate/http: ^5.8|^6.0|^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.17
- phpunit/phpunit: ^9.5
- psalm/plugin-laravel: ^1.4
- vimeo/psalm: ^4.3
README
With this package you can easily register referrals for your users/models.
Installation
You can install the package via composer:
gfdfasdfsfds
Usage
This example shows an users (App\Models\User
) who can have multiple referralAccounts
. Based on orders (App\Models\Order
) made in the system it will register the referral for the referral account.
Add the CanReferralContract
& CanReferralTrait
in App\Models\User
;
<?php namespace App\Models; use Famdirksen\LaravelReferral\Contracts\CanReferralContract; use Famdirksen\LaravelReferral\Traits\CanReferralTrait; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable implements CanReferralContract { use CanReferralTrait; // }
Add the HandleReferralContract
& HandleReferralTrait
in App\Models\Order
;
<?php namespace App; use Famdirksen\LaravelReferral\Contracts\HandleReferralContract; use Famdirksen\LaravelReferral\Traits\HandleReferralTrait; use Illuminate\Database\Eloquent\Model; class Order extends Model implements HandleReferralContract { use HandleReferralTrait; // }
Last, you need to register the middleware that's keeping track of the referrals.
Add the CheckReferralMiddleware
to App\Http\Kernel
:
<?php namespace App\Http; use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel { protected $middlewareGroups = [ 'web' => [ // \Famdirksen\LaravelReferral\Http\Middleware\CheckReferralMiddleware::class, // ], ]; // }
Get all referralAccounts for the current authenticated user:
$user = auth()->user(); $user->referralAccounts();
Configuration
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.