Completed
Push — badges-system ( 750538...a7f9ad )
by Fèvre
02:19
created

User::comments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Models;
3
4
use Eloquence\Behaviours\Sluggable;
5
use Illuminate\Auth\Authenticatable;
6
use Illuminate\Auth\Passwords\CanResetPassword;
7
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
8
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
9
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
10
use Illuminate\Database\Eloquent\SoftDeletes;
11
use Illuminate\Foundation\Auth\Access\Authorizable;
12
use Illuminate\Notifications\DatabaseNotification;
13
use Illuminate\Notifications\Notifiable;
14
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
15
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMediaConversions;
16
use Ultraware\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
17
use Ultraware\Roles\Traits\HasRoleAndPermission;
18
use Xetaravel\Models\Entities\UserEntity;
19
use Xetaravel\Models\Presenters\UserPresenter;
20
21
class User extends Model implements
22
    AuthenticatableContract,
23
    AuthorizableContract,
24
    CanResetPasswordContract,
25
    HasRoleAndPermissionContract,
26
    HasMediaConversions
27
{
28
    use Authenticatable,
29
        Authorizable,
30
        CanResetPassword,
31
        Notifiable,
32
        SoftDeletes,
33
        Sluggable,
34
        HasRoleAndPermission,
35
        HasMediaTrait,
36
        UserEntity,
37
        UserPresenter;
38
39
    /**
40
     * The attributes that are mass assignable.
41
     *
42
     * @var array
43
     */
44
    protected $fillable = [
45
        'username',
46
        'email',
47
        'password',
48
        'slug',
49
        'register_ip',
50
        'last_login_ip',
51
        'last_login'
52
    ];
53
54
    /**
55
     * The attributes that should be hidden for arrays.
56
     *
57
     * @var array
58
     */
59
    protected $hidden = [
60
        'password',
61
        'remember_token'
62
    ];
63
64
    /**
65
     * The accessors to append to the model's array form.
66
     *
67
     * @var array
68
     */
69
    protected $appends = [
70
        'profile_background',
71
        
72
        // Media Model
73
        'avatar_small',
74
        'avatar_medium',
75
        'avatar_big',
76
        
77
        // Account Model
78
        'first_name',
79
        'last_name',
80
        'biography',
81
        'signature',
82
        'facebook',
83
        'twitter'
84
    ];
85
86
    /**
87
     * The attributes that should be mutated to dates.
88
     *
89
     * @var array
90
     */
91
    protected $dates = [
92
        'deleted_at'
93
    ];
94
95
    /**
96
     * Return the field to slug.
97
     *
98
     * @return string
99
     */
100
    public function slugStrategy(): string
101
    {
102
        return 'username';
103
    }
104
105
    /**
106
     * Register the related to the Model.
107
     *
108
     * @return void
109
     */
110
    public function registerMediaConversions()
111
    {
112
        $this->addMediaConversion('thumbnail.small')
113
                ->width(100)
114
                ->height(100)
115
                ->keepOriginalImageFormat();
116
        
117
        $this->addMediaConversion('thumbnail.medium')
118
                ->width(200)
119
                ->height(200)
120
                ->keepOriginalImageFormat();
121
        
122
        $this->addMediaConversion('thumbnail.big')
123
                ->width(300)
124
                ->height(300)
125
                ->keepOriginalImageFormat();
126
        
127
        $this->addMediaConversion('original')
128
                ->keepOriginalImageFormat();
129
    }
130
131
    /**
132
     * Get the comments for the user.
133
     *
134
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
135
     */
136
    public function comments()
137
    {
138
        return $this->hasMany(Comment::class);
139
    }
140
141
    /**
142
     * Get the articles for the user.
143
     *
144
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
145
     */
146
    public function articles()
147
    {
148
        return $this->hasMany(Article::class);
149
    }
150
151
    /**
152
     * Get the account for the user.
153
     *
154
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
155
     */
156
    public function account()
157
    {
158
        return $this->hasOne(Account::class);
159
    }
160
161
    /**
162
     * Get the roles for the user.
163
     *
164
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
165
     */
166
    public function roles()
167
    {
168
        return $this->belongsToMany(\Ultraware\Roles\Models\Role::class);
169
    }
170
171
    /**
172
     * Get the badges for the user.
173
     *
174
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
175
     */
176
    public function badges()
177
    {
178
        return $this->belongsToMany(Badge::class)->withTimestamps();
179
    }
180
181
    /**
182
     * Get the notifications for the user.
183
     *
184
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
185
     */
186
    public function notifications()
187
    {
188
        return $this->morphMany(DatabaseNotification::class, 'notifiable')
189
                        ->orderBy('read_at', 'asc')
190
                        ->orderBy('created_at', 'desc');
191
    }
192
}
193