Laravel

Fortify: Custom User Login Request

  - 1 min read
Fortify: Custom User Login Request

Fortify allows to customize user Login process, this can be done by implementing customLogin method in FortifyServiceProvider.

Fortify::authenticateUsing(function (LoginRequest $request) {
    // ...
}

However this implementation uses FortifyLoginRequest, and what we need is to use a custom request instead.

Solution:

1. create the CustomLoginRequest wich implements Fortify's LoginRequest:

class CustomLoginRequest extends \Laravel\Fortify\Http\Requests\LoginRequest
{
    public function rules(): array
        {
            return [
                // your rules here
            ];
        }
}

2. In FortifyServiceProvider, override Fortify's default request:

$this->app->bind(\Laravel\Fortify\Http\Requests\LoginRequest::class, CustomLoginRequest::class);

Fortify::authenticateUsing(function (CustomLoginRequest $request) {
    // ...
}
Copyright © - 2013 ismaail.com. All rights reserved.