Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Target [laravelfortifycontractsloginviewresponse] is not instantiable.


Target [laravel\fortify\contracts\loginviewresponse] is not instantiable.


The error "target [laravel\fortify\contracts\loginviewresponse] is not instantiable" typically occurs when you're trying to bind a custom `LoginViewResponse` class to the `LoginViewResponseContract` in your `FortifyServiceProvider`, but the `LoginViewResponse` class is not properly implemented.

To resolve this issue, you can follow these steps:

1. Create a custom `LoginViewResponse` class:
- Create a new file called `LoginViewResponse.php` in your `app/Http/Responses/Fortify` directory.
- Implement the `LoginViewResponseContract` interface and override the `toResponse` method.

php
<?php

namespace App\Http\Responses\Fortify;

use Illuminate\Contracts\Support\Responsable;
use Laravel\Fortify\Contracts\LoginViewResponse as LoginViewResponseContract;

class LoginViewResponse implements LoginViewResponseContract
{
    /**
     * Create an HTTP response that represents the object.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function toResponse($request)
    {
        // Customize the login view response here
        return view('auth.login');
    }
}

2. Register the custom `LoginViewResponse` class:
- Open your `app/Providers/FortifyServiceProvider.php` file.
- In the `boot` method, bind the `LoginViewResponseContract` to your custom `LoginViewResponse` class.

php
<?php

namespace App\Providers;

use App\Http\Responses\Fortify\LoginViewResponse;
use Laravel\Fortify\Contracts\LoginViewResponse as LoginViewResponseContract;
use Laravel\Fortify\Fortify;
use Illuminate\Support\ServiceProvider;

class FortifyServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Fortify::createUsersUsing(CreateNewUser::class);
        Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
        Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
        Fortify::resetUserPasswordsUsing(ResetUserPassword::class);

        Fortify::loginView(function () {
            return view('auth.login');
        });

        $this->app->bind(LoginViewResponseContract::class, LoginViewResponse::class);
    }
}

The error "target [laravel\fortify\contracts\loginviewresponse] is not instantiable" occurs because the `LoginViewResponseContract` is an interface, and you need to provide a concrete implementation of it. By creating a custom `LoginViewResponse` class and binding it to the `LoginViewResponseContract`, you should be able to resolve the issue.

Make sure that your `LoginViewResponse` class correctly implements the `toResponse` method and returns the appropriate response for your application.