|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: alive |
|
5
|
|
|
* Date: 12/11/17 |
|
6
|
|
|
* Time: 7:55 AM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Alive2212\LaravelModelEventService\Events; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Queue\SerializesModels; |
|
12
|
|
|
use Illuminate\Broadcasting\PrivateChannel; |
|
13
|
|
|
use Illuminate\Foundation\Events\Dispatchable; |
|
14
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class BaseModelPivotEvent |
|
18
|
|
|
{ |
|
19
|
|
|
use Dispatchable, InteractsWithSockets, SerializesModels; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $model; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $relationName; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $pivotIds; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $pivotIdsAttributes; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Create a new event instance. |
|
43
|
|
|
* @param $params |
|
44
|
|
|
* @internal param $model |
|
45
|
|
|
* @internal param $relationName |
|
46
|
|
|
* @internal param $pivotIds |
|
47
|
|
|
* @internal param $pivotIdsAttributes |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct($params) |
|
50
|
|
|
{ |
|
51
|
|
|
$counter = 0; |
|
52
|
|
|
foreach ($params as $param) { |
|
53
|
|
|
switch ($counter){ |
|
54
|
|
|
case 0: |
|
55
|
|
|
$this->model = $param; |
|
56
|
|
|
break; |
|
57
|
|
|
case 1: |
|
58
|
|
|
$this->relationName = $param; |
|
59
|
|
|
break; |
|
60
|
|
|
case 2: |
|
61
|
|
|
$this->pivotIds = $param; |
|
62
|
|
|
break; |
|
63
|
|
|
case 3: |
|
64
|
|
|
$this->pivotIdsAttributes = $param; |
|
65
|
|
|
break; |
|
66
|
|
|
} |
|
67
|
|
|
$counter+=1; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the channels the event should broadcast on. |
|
73
|
|
|
* |
|
74
|
|
|
* @return PrivateChannel |
|
75
|
|
|
*/ |
|
76
|
|
|
public function broadcastOn() |
|
77
|
|
|
{ |
|
78
|
|
|
return new PrivateChannel('channel-name'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return mixed |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getModel() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->model; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param mixed $model |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setModel($model) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->model = $model; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return mixed |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getRelationName() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->relationName; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param mixed $relationName |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setRelationName($relationName) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->relationName = $relationName; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return mixed |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getPivotIds() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->pivotIds; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param mixed $pivotIds |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setPivotIds($pivotIds) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->pivotIds = $pivotIds; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return mixed |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getPivotIdsAttributes() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->pivotIdsAttributes; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param mixed $pivotIdsAttributes |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setPivotIdsAttributes($pivotIdsAttributes) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->pivotIdsAttributes = $pivotIdsAttributes; |
|
143
|
|
|
} |
|
144
|
|
|
} |