LinkStack/app/Models/User.php

84 lines
1.9 KiB
PHP
Raw Normal View History

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;
use Illuminate\Support\Str;
2021-04-16 01:00:00 +02: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',
'image',
2021-04-16 01:00:00 +02:00
'password',
'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',
];
public function visits()
{
return visits($this)->relation();
}
public function socialAccounts()
{
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 17:11:35 +01:00
$minIdValue = 10**($numberOfDigits - 1);
$maxIdValue = 10**$numberOfDigits - 1;
2023-12-01 17:11:35 +01:00
do {
$randomId = rand($minIdValue, $maxIdValue);
} while (User::find($randomId));
2023-12-01 17:11:35 +01:00
$user->id = $randomId;
}
}
});
}
2021-04-16 01:00:00 +02:00
}