'Upgrading from Laravel 5.5 to Laravel 9

I am upgrading an Laravel version for an old project. But I have encountered an issues with updating the AuthServiceProvider. It looks like the "validator()" method on line "Password::broker()->validator(function ($credentials) {" has been removed. Could someone give me a suggestion on how to fix it in the upgrade? I could do it differently, but I wanted to know if there was a new way to use the "validator()" method.


namespace App\Providers;

use App\Http\Forms\Sites\Login;
use App\Http\Forms\ResetPassword;
use App\Http\Forms\ForgotPassword;
use Illuminate\Support\Facades\Password;
use Stone\Forms\Handlers\LaravelFormBuilder;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;


class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        $this->app['forms']->register(
            'forgot-password',
            new LaravelFormBuilder(view(), ForgotPassword::class)
        );

        $this->app['forms']->register(
            'reset-password',
            new LaravelFormBuilder(view(), ResetPassword::class)
        );

        $this->app['forms']->register(
            'site-login',
            new LaravelFormBuilder(view(), Login::class)
        );

        Password::broker()->validator(function ($credentials) {
            return $credentials['password'] === $credentials['password_confirmation'];
        });
    }
}


Solution 1:[1]

You can use the following in Laravel 9 to validate your password.

$validator = Validator::make($request->all(), [
    'password' => ['required', 'confirmed', Password::min(8)],
    'password_confirmation' = 'same:password'
]);

I hope this answers your question.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manuel Barretto