update codigo referido funcionamiento login, register y dashboard
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@@ -22,6 +23,12 @@ class User extends Authenticatable
|
||||
'rol_id',
|
||||
'subvendedor_id',
|
||||
'subvendedor',
|
||||
|
||||
'referral_code',
|
||||
'parent_id',
|
||||
|
||||
|
||||
'rank_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -107,4 +114,36 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasMany(User::class, 'subvendedor_id');
|
||||
}
|
||||
|
||||
// Referral relationships
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(User::class, 'parent_id')->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
// public function rank()
|
||||
// {
|
||||
// return $this->belongsTo(Rank::class);
|
||||
// }
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($user) {
|
||||
if (empty($user->referral_code)) {
|
||||
do {
|
||||
$code = strtoupper(Str::random(8));
|
||||
} while (self::where('referral_code', $code)->exists());
|
||||
|
||||
$user->referral_code = $code;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user