Referral Meta

This commit is contained in:
David Bomba 2024-06-19 12:45:42 +10:00
parent dc1ca43514
commit cb9e40d442
4 changed files with 49 additions and 0 deletions

View File

@ -449,6 +449,23 @@ class MultiDB
return false;
}
public static function findUserByReferralCode(string $referral_code): ?User
{
$current_db = config('database.default');
foreach (self::$dbs as $db) {
if ($user = User::on($db)->where('referral_code', $referral_code)->first()) {
self::setDb($db);
return $user;
}
}
self::setDB($current_db);
return false;
}
public static function findAndSetDbByClientId($client_id): ?Client
{
$current_db = config('database.default');

View File

@ -67,6 +67,7 @@ use Laracasts\Presenter\PresentableTrait;
* @property string|null $custom_value2
* @property string|null $custom_value3
* @property string|null $custom_value4
* @property object|null $referral_meta
* @property int|null $created_at
* @property int|null $updated_at
* @property int|null|Carbon $deleted_at
@ -181,6 +182,7 @@ class User extends Authenticatable implements MustVerifyEmail
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
'oauth_user_token_expiry' => 'datetime',
'referral_meta' => 'object',
];
public function name()
@ -680,4 +682,5 @@ class User extends Authenticatable implements MustVerifyEmail
{
return ctrans('texts.user');
}
}

View File

@ -66,6 +66,7 @@ class UserTransformer extends EntityTransformer
'language_id' => (string) $user->language_id ?: '',
'user_logged_in_notification' => (bool) $user->user_logged_in_notification,
'referral_code' => (string) $user->referral_code,
'referral_meta' => $user->referral_meta ? (object)$user->referral_meta : new \stdClass,
];
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->mediumText('referral_meta')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};