-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I override a method in Toaster class #121
Comments
Also I whould like to shere my modification, It may help someone. In setDefaultConfig method I added 'showClass' & 'hideClass', So I can set a default animation. |
Hey @o4itea , It's very simple just like we override any parent class function in derived class. You can try following : Create a child class extending Toaster class and override the "setDefaultConfig" and "middleware" methods. use RealRashid\SweetAlert;
Class ChildClass extends Toaster {
public function setDefaultConfig () {
// Write your logic here
}
public function middleware () {
// Write your logic here
}
} Hope this will help. |
Thank Bro, |
Create the Service Provider for overridden class. use RealRashid\SweetAlert;
use app\ChildClass;
Class ChildClassServiceProvider extends ServiceProvider {
public function register(){
$this->app->bind('alert', function(){
return new ChildClass($this->app['config']);
})
}
} Complete Code: // ChildClass
use RealRashid\SweetAlert;
Class ChildClass extends Toaster {
public function setDefaultConfig () {
// Write your logic here
}
public function middleware () {
// Write your logic here
}
} // ServiceProvider
use RealRashid\SweetAlert;
use app\ChildClass;
Class ChildClassServiceProvider extends ServiceProvider {
public function register(){
$this->app->bind('alert', function(){
return new ChildClass($this->app['config']);
})
}
} |
Thanks Rashid, You've lighted the way in front of me. The following code works // ServiceProvider
use App\ChildClass;
Class ChildClassServiceProvider extends ServiceProvider {
public function register(){
$this->app->bind('alert', ChildClass::class)
}
} or replace the facade with the targeted class // ServiceProvider
use RealRashid\SweetAlert\Toaster;
use App\ChildClass;
Class ChildClassServiceProvider extends ServiceProvider {
public function register(){
$this->app->bind(Toaster::class, ChildClass::class)
}
} |
Hi,
I want to make a bit modification on "setDefaultConfig" and "middleware" methods in Toaster class.
How I can do that and where should I place my modification without touch the original files.
Sorry to post this here if it not related to issues.
Thanks
The text was updated successfully, but these errors were encountered: