1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arcanedev\LaravelMessenger\Models; |
6
|
|
|
|
7
|
|
|
use Arcanedev\LaravelMessenger\Contracts\Participation as ParticipantContract; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Participant |
11
|
|
|
* |
12
|
|
|
* @package Arcanedev\LaravelMessenger\Models |
13
|
|
|
* @author ARCANEDEV <[email protected]> |
14
|
|
|
* |
15
|
|
|
* @property int id |
16
|
|
|
* @property int discussion_id |
17
|
|
|
* @property \Arcanedev\LaravelMessenger\Models\Discussion discussion |
18
|
|
|
* @property string participable_type |
19
|
|
|
* @property int participable_id |
20
|
|
|
* @property \Illuminate\Database\Eloquent\Model participable |
21
|
|
|
* @property \Illuminate\Support\Carbon last_read |
22
|
|
|
* @property \Illuminate\Support\Carbon created_at |
23
|
|
|
* @property \Illuminate\Support\Carbon updated_at |
24
|
|
|
* @property \Illuminate\Support\Carbon deleted_at |
25
|
|
|
*/ |
26
|
|
|
class Participation extends Model implements ParticipantContract |
27
|
|
|
{ |
28
|
|
|
/* ----------------------------------------------------------------- |
29
|
|
|
| Properties |
30
|
|
|
| ----------------------------------------------------------------- |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The attributes that can be set with Mass Assignment. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $fillable = [ |
39
|
|
|
'discussion_id', |
40
|
|
|
'participable_type', |
41
|
|
|
'participable_id', |
42
|
|
|
'last_read', |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The attributes that should be mutated to dates. |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $dates = ['last_read', 'deleted_at']; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The attributes that should be cast to native types. |
54
|
|
|
* |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $casts = [ |
58
|
|
|
'id' => 'integer', |
59
|
|
|
'discussion_id' => 'integer', |
60
|
|
|
'participable_id' => 'integer', |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/* ----------------------------------------------------------------- |
64
|
|
|
| Constructor |
65
|
|
|
| ----------------------------------------------------------------- |
66
|
|
|
*/ |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Create a new Eloquent model instance. |
70
|
|
|
* |
71
|
|
|
* @param array $attributes |
72
|
|
|
*/ |
73
|
186 |
|
public function __construct(array $attributes = []) |
74
|
|
|
{ |
75
|
186 |
|
$this->setTable( |
76
|
186 |
|
config('messenger.participations.table', 'participations') |
77
|
|
|
); |
78
|
|
|
|
79
|
186 |
|
parent::__construct($attributes); |
80
|
186 |
|
} |
81
|
|
|
|
82
|
|
|
/* ----------------------------------------------------------------- |
83
|
|
|
| Relationships |
84
|
|
|
| ----------------------------------------------------------------- |
85
|
|
|
*/ |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Discussion relationship. |
89
|
|
|
* |
90
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
91
|
|
|
*/ |
92
|
6 |
|
public function discussion() |
93
|
|
|
{ |
94
|
6 |
|
return $this->belongsTo( |
95
|
6 |
|
config('messenger.discussions.model', Discussion::class) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Participable relationship. |
101
|
|
|
* |
102
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
103
|
|
|
*/ |
104
|
54 |
|
public function participable() |
105
|
|
|
{ |
106
|
54 |
|
return $this->morphTo(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/* ----------------------------------------------------------------- |
110
|
|
|
| Getters & Setters |
111
|
|
|
| ----------------------------------------------------------------- |
112
|
|
|
*/ |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get the participable string info. |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
6 |
|
public function stringInfo() |
120
|
|
|
{ |
121
|
6 |
|
return $this->participable->getAttribute('name'); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|