Completed
Push — develop ( cc9a49...c1329f )
by Abdelrahman
09:49
created

Socialite::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Models;
6
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Builder;
9
use Illuminate\Database\Eloquent\Relations\MorphTo;
10
11
/**
12
 * Cortex\Fort\Models\Socialite.
13
 *
14
 * @property int                                                $id
15
 * @property int                                                $user_id
16
 * @property string                                             $user_type
17
 * @property string                                             $provider
18
 * @property string                                             $provider_uid
19
 * @property \Carbon\Carbon|null                                $created_at
20
 * @property \Carbon\Carbon|null                                $updated_at
21
 * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $user
22
 *
23
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\Socialite whereCreatedAt($value)
24
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\Socialite whereId($value)
25
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\Socialite whereProvider($value)
26
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\Socialite whereProviderUid($value)
27
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\Socialite whereUpdatedAt($value)
28
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\Socialite whereUserId($value)
29
 * @method static \Illuminate\Database\Eloquent\Builder|\Cortex\Fort\Models\Socialite whereUserType($value)
30
 * @mixin \Eloquent
31
 */
32
class Socialite extends Model
33
{
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected $fillable = [
38
        'user_id',
39
        'user_type',
40
        'provider',
41
        'provider_uid',
42
    ];
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected $casts = [
48
        'user_id' => 'integer',
49
        'user_type' => 'string',
50
        'provider' => 'string',
51
        'provider_uid' => 'string',
52
    ];
53
54
    /**
55
     * Create a new Eloquent model instance.
56
     *
57
     * @param array $attributes
58
     */
59
    public function __construct(array $attributes = [])
60
    {
61
        parent::__construct($attributes);
62
63
        $this->setTable(config('cortex.fort.tables.socialites'));
64
    }
65
66
    /**
67
     * Get the owning user.
68
     *
69
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
70
     */
71
    public function user(): MorphTo
72
    {
73
        return $this->morphTo();
74
    }
75
76
    /**
77
     * Get socialites of the given user.
78
     *
79
     * @param \Illuminate\Database\Eloquent\Builder $builder
80
     * @param \Illuminate\Database\Eloquent\Model   $user
81
     *
82
     * @return \Illuminate\Database\Eloquent\Builder
83
     */
84
    public function scopeOfUser(Builder $builder, Model $user): Builder
85
    {
86
        return $builder->where('user_type', $user->getMorphClass())->where('user_id', $user->getKey());
87
    }
88
}
89