-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathUser.php
69 lines (57 loc) · 1.59 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Recca0120\LaravelErd\Tests\Fixtures\Models;
use Awobaz\Compoships\Compoships;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Spatie\Permission\Traits\HasRoles;
class User extends Model
{
use Compoships;
use HasRoles;
protected $fillable = ['name', 'email', 'password'];
/**
* Get the phone associated with the user.
*/
public function phone(): HasOne
{
return $this->hasOne(Phone::class);
}
public function latestPost(): HasOne
{
return $this->hasOne(Post::class)->latestOfMany();
}
public function oldestPost(): HasOne
{
return $this->hasOne(Post::class)->oldestOfMany();
}
public function posts(): HasMany
{
return $this->hasMany(Post::class);
}
/**
* Get the user's image.
*/
public function image(): MorphOne
{
return $this->morphOne(Image::class, 'imageable');
}
/**
* Get the user's images.
*/
public function images(): MorphMany
{
return $this->morphMany(Image::class, 'imageable');
}
public function devices(): BelongsToMany
{
return $this->belongsToMany(Device::class, 'user_device');
}
public function tasks()
{
return $this->hasMany(Task::class, ['team_id', 'category_id'], ['team_id', 'category_id']);
}
}