amir5's avatar
Level 7

How to call overrided boot method inside of trait?

I want to automatically create tracking_code when I save model so, I've put in boot method, and extracted that to a trait. Now I want to add extra things to boot method, and when I define that it overrides my trait implementation....

0 likes
1 reply
JussiMannisto's avatar
Level 50

Alias the trait method, then call that in your new method:

trait MyTrait {
	function foo() {
		dump('Original method called.');
	}
}

class MyClass {

	use MyTrait {
		foo as originalFoo;
	}

	function foo() {
		$this->originalFoo();
		dump('New method called.');
	}
	
}

1 like

Please or to participate in this conversation.