@@ -14,11 +14,13 @@ protected static function registerModelEvent($event, $callback)
14
14
{
15
15
parent ::registerModelEvent ($ event , $ callback );
16
16
17
- if (static ::class === self ::class && property_exists (self ::class, 'childTypes ' )) {
17
+ $ childTypes = (new self )->getChildTypes ();
18
+
19
+ if (static ::class === self ::class && $ childTypes !== []) {
18
20
// We don't want to register the callbacks that happen in the boot method of the parent, as they'll be called
19
21
// from the child's boot method as well.
20
22
if (! self ::parentIsBooting ()) {
21
- foreach (( new self )-> childTypes as $ childClass ) {
23
+ foreach ($ childTypes as $ childClass ) {
22
24
if ($ childClass !== self ::class) {
23
25
$ childClass ::registerModelEvent ($ event , $ callback );
24
26
}
@@ -193,10 +195,10 @@ protected function getChildModel(array $attributes)
193
195
*/
194
196
public function classFromAlias ($ aliasOrClass )
195
197
{
196
- if ( property_exists ( $ this , ' childTypes ' )) {
197
- if ( isset ( $ this -> childTypes [ $ aliasOrClass ])) {
198
- return $ this -> childTypes [$ aliasOrClass ];
199
- }
198
+ $ childTypes = $ this -> getChildTypes ();
199
+
200
+ if ( isset ( $ childTypes [$ aliasOrClass ])) {
201
+ return $ childTypes [ $ aliasOrClass ];
200
202
}
201
203
202
204
return $ aliasOrClass ;
@@ -208,10 +210,10 @@ public function classFromAlias($aliasOrClass)
208
210
*/
209
211
public function classToAlias ($ className )
210
212
{
211
- if ( property_exists ( $ this , ' childTypes ' )) {
212
- if ( in_array ( $ className , $ this -> childTypes )) {
213
- return array_search ( $ className , $ this -> childTypes );
214
- }
213
+ $ childTypes = $ this -> getChildTypes ();
214
+
215
+ if ( in_array ( $ className , $ childTypes )) {
216
+ return array_search ( $ className , $ childTypes );
215
217
}
216
218
217
219
return $ className ;
0 commit comments