Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kisaw88's avatar

How to know where to override vendor methods

How to know where to override vendor methods , for example i want to override a method in \Illuminate\Auth\Passwords\PasswordBroker validatePasswordWithDefaults

but i don't know where to write it ?

0 likes
3 replies
Cronix's avatar

Look into binding classes into the service container. You'd bind your class instead of the original.

An example

public function register()
{
    $this->app->singleton(
        // the original class
        'Laravel\Spark\Contracts\Interactions\Settings\Profile\UpdateContactInformation',
        // my custom class
        'App\Http\SparkExtensions\UpdateContactInformation'
    );
}

That basically tells laravel "whenever an instance of Laravel\Spark.....\UpdateContractInformation (which is in /vendor/Laravel/Spark...) is called, give an instance of App\Http\SparkExtensions\UpdateContactInformation instead" https://laravel.com/docs/5.7/container

The custom App\Http....\UpdateContactInformation class extends the original Laravel\Spark.....\UpdateContractInformation class to inherit the methods, and then I just override what I need in the custom class.

4 likes
kisaw88's avatar

@CRONIX - okay, but the problem that i'am facing now that i don't know where to write this binding exactly in the service provider ?

Please or to participate in this conversation.