Skip to content
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

Allow Fortify::xxView to render custom responses #33

Closed
hailwood opened this issue Sep 14, 2020 · 2 comments
Closed

Allow Fortify::xxView to render custom responses #33

hailwood opened this issue Sep 14, 2020 · 2 comments

Comments

@hailwood
Copy link

Right now if we want to change the login view we can do

Fortify::loginView('different-view')

But that only allows you to change it to a different view name, behind the scenes it's just rendering a singleton binding for LoginViewResponse.

You'd think no stress, we can override that binding for example for an Inertia view

$this->app->singleton(LoginViewResponse::class, () => Inertia::render('Login'));

But unfortunately this doesn't work due to the typehint on the controller method

So instead the next best option is resolving an anonymous class that proxies the inertia response

$this->app->singleton(LoginViewResponse::class, function () {
    return new class implements LoginViewResponse
    {
        public function toResponse($request)
        {
            return Inertia::render('Login')->toResponse($request);
        }
    };
});

This works perfectly but isn't exactly friendly.
My suggestion is that we loosen the typehint to just Response and allow Fortify::loginView to take a closure which would be used as the binding, meaning it would be as simple as

Fortify::loginView(() => Inertia::render('Login'));

Of course we'd do the same for the other view methods. I'm happy to PR this if the idea gets approved.

@hailwood
Copy link
Author

@stephensamra
Copy link

https://blog.laravel.com/jetstream-customization-and-password-confirmation

Is there a solution (other than the anonymous class workaround above) if you're using Fortify without Jetstream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants