Skip to content

Commit

Permalink
Allow tracking of affiliate/referral code use
Browse files Browse the repository at this point in the history
  • Loading branch information
cholladay0816 committed Aug 25, 2023
1 parent 8e09594 commit ee9038e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
4 changes: 4 additions & 0 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Actions\Fortify;

use App\Models\Affiliate;
use App\Models\Team;
use App\Models\User;
use App\Rules\LocationRule;
use App\Rules\ReCaptchaRule;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\CreatesNewUsers;
Expand Down Expand Up @@ -38,10 +40,12 @@ public function create(array $input)
])->validate();

return DB::transaction(function () use ($input) {
$referral = Affiliate::where('code', Session::get('affiliate_code'))->first();
return tap(User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
'affiliate_id' => $referral?->id
]), function (User $user) {
$this->createTeam($user);
});
Expand Down
8 changes: 7 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class User extends Authenticatable implements MustVerifyEmail
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name', 'email', 'password', 'affiliate_id'
];

/**
Expand All @@ -46,6 +46,7 @@ class User extends Authenticatable implements MustVerifyEmail
'remember_token',
'two_factor_recovery_codes',
'two_factor_secret',
'google_id',
];

/**
Expand Down Expand Up @@ -93,6 +94,11 @@ public function incentives()
return $this->hasMany(Incentive::class);
}

public function affiliate()
{
return $this->belongsTo(Affiliate::class);
}

public function bonuses()
{
return $this->hasMany(Bonus::class);
Expand Down
8 changes: 4 additions & 4 deletions app/Nova/Bonus.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Currency;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Http\Requests\NovaRequest;

class Bonus extends Resource
Expand All @@ -33,7 +33,7 @@ class Bonus extends Resource
* @var array
*/
public static $search = [
'id', 'user_id', 'amount', 'commission_id'
'id', 'user_id', 'amount', 'commission_id', 'reason'
];

public static function indexQuery(NovaRequest $request, $query)
Expand All @@ -54,9 +54,9 @@ public function fields(Request $request)
{
return [
ID::make(__('ID'), 'id')->sortable(),
BelongsTo::make('User'),
BelongsTo::make('User')->sortable()->filterable(),
BelongsTo::make('Commission'),
Number::make('Amount')
Currency::make('Amount')->asMinorUnits()->sortable()
];
}

Expand Down
8 changes: 5 additions & 3 deletions app/Nova/Incentive.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Currency;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class Incentive extends Resource
Expand Down Expand Up @@ -54,8 +55,9 @@ public function fields(Request $request)
{
return [
ID::make(__('ID'), 'id')->sortable(),
BelongsTo::make('User'),
Number::make('Amount')
BelongsTo::make('User')->sortable()->filterable(),
Currency::make('Amount')->asMinorUnits()->sortable()->filterable(),
Text::make('Reason')->nullable()
];
}

Expand Down
13 changes: 8 additions & 5 deletions app/Nova/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Http\Request;
use Illuminate\Validation\Rules;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Gravatar;
Expand Down Expand Up @@ -80,22 +81,24 @@ public function fields(NovaRequest $request)
->creationRules('unique:users,email')
->updateRules('unique:users,email,{{resourceId}}'),

Boolean::make('Onboarded', 'onboarded_at')->onlyOnIndex(),
Boolean::make('Onboarded', 'onboarded_at')->onlyOnIndex()->sortable()->filterable(),
BelongsTo::make('Affiliate')->nullable()->sortable()->filterable(),

Password::make('Password')
->onlyOnForms()
->creationRules('required', Rules\Password::defaults())
->updateRules('nullable', Rules\Password::defaults()),

Text::make('Stripe Customer ID', 'stripe_id'),
Text::make('Stripe Account ID'),
Text::make('Stripe Customer ID', 'stripe_id')->hideFromIndex(),
Text::make('Stripe Account ID')->hideFromIndex(),
Text::make('Google ID')->nullable()->hideFromIndex(),

HasMany::make('Roles', 'roles', 'App\Nova\Role'),
HasMany::make('Reports', 'reports', 'App\Nova\Report'),
HasMany::make('Strikes', 'strikes', 'App\Nova\Strike'),
HasMany::make('Suspensions', 'suspensions', 'App\Nova\Suspension'),
DateTime::make('Created At')->sortable(),
DateTime::make('Updated At')->sortable(),
DateTime::make('Created At')->sortable()->filterable(),
DateTime::make('Updated At')->sortable()->filterable(),
DateTime::make('Onboarded At')->nullable()->sortable()->filterable()
];
}
Expand Down
1 change: 1 addition & 0 deletions resources/views/layouts/agnostic.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function gtag(){dataLayer.push(arguments);}
@stack('modals')

@livewireScripts
<livewire:referral-interceptor/>
<div class="fixed bottom-0 inset-x-0 pb-2 sm:pb-5">
<div class="max-w-7xl mx-auto px-2 sm:px-6 lg:px-8">
@if(session()->has('success'))
Expand Down
1 change: 1 addition & 0 deletions resources/views/layouts/guest.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ function gtag(){dataLayer.push(arguments);}
@stack('modals')

@livewireScripts
<livewire:referral-interceptor/>
</body>
</html>

0 comments on commit ee9038e

Please sign in to comment.