1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\ActiveRecord; |
4
|
|
|
|
5
|
|
|
use Ffcms\Core\Arch\ActiveModel; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class WallPost. Active record model for user wall posts |
9
|
|
|
* @package Apps\ActiveRecord |
10
|
|
|
* @property int $id |
11
|
|
|
* @property int $target_id |
12
|
|
|
* @property int $sender_id |
13
|
|
|
* @property string $message |
14
|
|
|
* @property string $created_at |
15
|
|
|
* @property string $updated_at |
16
|
|
|
* @property User $user |
17
|
|
|
* @property User $senderUser |
18
|
|
|
* @property User $targetUser |
19
|
|
|
* @property WallAnswer[] $answers |
20
|
|
|
*/ |
21
|
|
|
class WallPost extends ActiveModel |
22
|
|
|
{ |
23
|
|
|
protected $casts = [ |
24
|
|
|
'id' => 'integer', |
25
|
|
|
'target_id' => 'integer', |
26
|
|
|
'sender_id' => 'integer', |
27
|
|
|
'message' => 'string' |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get wall post answers relation |
32
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
33
|
|
|
*/ |
34
|
|
|
public function answers() |
35
|
|
|
{ |
36
|
|
|
return $this->hasMany(WallAnswer::class, 'post_id'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get sender user object relation |
41
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
42
|
|
|
*/ |
43
|
|
|
public function senderUser() |
44
|
|
|
{ |
45
|
|
|
return $this->belongsTo(User::class, 'sender_id'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get target user object relation |
50
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
51
|
|
|
*/ |
52
|
|
|
public function targetUser() |
53
|
|
|
{ |
54
|
|
|
return $this->belongsTo(User::class, 'target_id'); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|