2021-04-16 01:00:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
2023-12-01 14:00:46 +01:00
|
|
|
use Illuminate\Support\Str;
|
2021-04-16 01:00:00 +02:00
|
|
|
|
2022-03-19 16:48:21 +01:00
|
|
|
class User extends Authenticatable implements MustVerifyEmail
|
2021-04-16 01:00:00 +02:00
|
|
|
{
|
|
|
|
use HasFactory, Notifiable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'email',
|
2022-11-08 16:11:59 +01:00
|
|
|
'image',
|
2021-04-16 01:00:00 +02:00
|
|
|
'password',
|
2022-11-08 16:11:59 +01:00
|
|
|
'provider',
|
|
|
|
'provider_id',
|
|
|
|
'email_verified_at',
|
|
|
|
'littlelink_name',
|
2021-04-16 01:00:00 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
|
|
|
'password',
|
|
|
|
'remember_token',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
];
|
2022-11-08 16:11:59 +01:00
|
|
|
|
|
|
|
public function visits()
|
|
|
|
{
|
|
|
|
return visits($this)->relation();
|
|
|
|
}
|
2023-12-01 14:00:46 +01:00
|
|
|
|
2022-11-08 16:11:59 +01:00
|
|
|
public function socialAccounts()
|
|
|
|
{
|
2023-12-01 14:00:46 +01:00
|
|
|
return $this->hasMany(SocialAccount::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
static::creating(function ($user) {
|
2023-12-01 17:11:35 +01:00
|
|
|
if (config('linkstack.disable_random_user_ids') != 'true') {
|
|
|
|
if (is_null(User::first())) {
|
|
|
|
$user->id = 1;
|
|
|
|
} else {
|
|
|
|
$numberOfDigits = config('linkstack.user_id_length') ?? 6;
|
2023-12-01 14:00:46 +01:00
|
|
|
|
2023-12-01 17:11:35 +01:00
|
|
|
$minIdValue = 10**($numberOfDigits - 1);
|
|
|
|
$maxIdValue = 10**$numberOfDigits - 1;
|
2023-12-01 14:00:46 +01:00
|
|
|
|
2023-12-01 17:11:35 +01:00
|
|
|
do {
|
|
|
|
$randomId = rand($minIdValue, $maxIdValue);
|
|
|
|
} while (User::find($randomId));
|
2023-12-01 14:00:46 +01:00
|
|
|
|
2023-12-01 17:11:35 +01:00
|
|
|
$user->id = $randomId;
|
|
|
|
}
|
|
|
|
}
|
2023-12-01 14:00:46 +01:00
|
|
|
});
|
2022-11-08 16:11:59 +01:00
|
|
|
}
|
2021-04-16 01:00:00 +02:00
|
|
|
}
|