1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CSlant\Blog\Core\Models; |
4
|
|
|
|
5
|
|
|
use AllowDynamicProperties; |
6
|
|
|
use CSlant\Blog\Core\Models\Base\BaseUser; |
7
|
|
|
use Illuminate\Database\Eloquent\Builder; |
8
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class User |
12
|
|
|
* |
13
|
|
|
* @package CSlant\Blog\Core\Models |
14
|
|
|
* |
15
|
|
|
* @property int $id |
16
|
|
|
* @property string $name |
17
|
|
|
* @property string $email |
18
|
|
|
* @property string $password |
19
|
|
|
* @property string $remember_token |
20
|
|
|
* @property string $first_name |
21
|
|
|
* @property string $last_name |
22
|
|
|
* @property string $username |
23
|
|
|
* @property object $permissions |
24
|
|
|
* @property string $avatar_url Property for avatar image url |
25
|
|
|
* @property int $posts_count |
26
|
|
|
* @property null|Role $roles |
27
|
|
|
* @property Post[] $posts |
28
|
|
|
* |
29
|
|
|
* @method static Builder|User newModelQuery() |
30
|
|
|
* @method static Builder|User newQuery() |
31
|
|
|
* @method static Builder|User query() |
32
|
|
|
* @method static Builder|User first() |
33
|
|
|
* @method static Builder|User find($id) |
34
|
|
|
* @method static Builder|User whereCreatedAt($value) |
35
|
|
|
* |
36
|
|
|
*/ |
37
|
|
|
#[AllowDynamicProperties] |
38
|
|
|
class User extends BaseUser |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* Defining an posts count accessor |
42
|
|
|
* ->posts_count |
43
|
|
|
* |
44
|
|
|
* @return int |
45
|
|
|
*/ |
46
|
|
|
public function getPostsCountAttribute(): int |
47
|
|
|
{ |
48
|
|
|
return $this->posts()->count(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function posts(): HasMany |
52
|
|
|
{ |
53
|
|
|
return $this->hasMany(Post::class, 'author_id'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|