Issues (157)

app/Models/User.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Contracts\Auth\MustVerifyEmail;
6
use Illuminate\Database\Eloquent\Factories\HasFactory;
7
use Illuminate\Foundation\Auth\User as Authenticatable;
8
use Illuminate\Notifications\Notifiable;
9
use Illuminate\Support\Str;
10
11
class User extends Authenticatable implements MustVerifyEmail
12
{
13
    use HasFactory, Notifiable;
0 ignored issues
show
The trait Illuminate\Notifications\Notifiable requires the property $email which is not provided by App\Models\User.
Loading history...
14
15
    /**
16
     * The attributes that are mass assignable.
17
     *
18
     * @var array
19
     */
20
    protected $fillable = [
21
        'name',
22
        'email',
23
        'image',
24
        'password',
25
        'provider',
26
        'provider_id',
27
        'email_verified_at',
28
        'littlelink_name',
29
    ];
30
31
    /**
32
     * The attributes that should be hidden for arrays.
33
     *
34
     * @var array
35
     */
36
    protected $hidden = [
37
        'password',
38
        'remember_token',
39
    ];
40
41
    /**
42
     * The attributes that should be cast to native types.
43
     *
44
     * @var array
45
     */
46
    protected $casts = [
47
        'email_verified_at' => 'datetime',
48
    ];
49
50
    public function visits()
51
    {
52
        return visits($this)->relation();
53
    }
54
55
    public function socialAccounts()
56
    {
57
        return $this->hasMany(SocialAccount::class);
58
    }
59
60
    protected static function boot()
61
    {
62
        parent::boot();
63
64
        static::creating(function ($user) {
65
            if (config('linkstack.disable_random_user_ids') != 'true') {
66
                if (is_null(User::first())) {
67
                    $user->id = 1;
68
                } else {
69
                    $numberOfDigits = config('linkstack.user_id_length') ?? 6;
70
    
71
                    $minIdValue = 10**($numberOfDigits - 1);
72
                    $maxIdValue = 10**$numberOfDigits - 1;
73
    
74
                    do {
75
                        $randomId = rand($minIdValue, $maxIdValue);
76
                    } while (User::find($randomId));
77
    
78
                    $user->id = $randomId;
79
                }
80
            }
81
        });
82
    }
83
}
84