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

[1.x] Allow Fortify views to accept Responsable objects #107

Merged
merged 2 commits into from
Oct 2, 2020
Merged

[1.x] Allow Fortify views to accept Responsable objects #107

merged 2 commits into from
Oct 2, 2020

Conversation

claudiodekker
Copy link
Contributor

@claudiodekker claudiodekker commented Oct 2, 2020

This fix allow methods such as Fortify::loginView to return (amongst others) an Inertia response without running into this error: Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given

This happens because Laravel's router calls ->toResponse() on Responsable, which SimpleViewResponse is an implementation of. After the object is converted to a response, other methods inside the router make sure that the response is properly generated.

However, because views such as Inertia's have their own Responsable implementation, this never gets triggered, because it never gets called by the SimpleViewResponse. This PR fixes this behaviour, preventing the user the need to do something like this:

Fortify::loginView(function (Request $request) {
    return Inertia::render('Auth/Login')->toResponse($request);
});

@reinink
Copy link

reinink commented Oct 2, 2020

Nice work @claudiodekker, this is a welcome change for Inertia.js users! ❤️

@driesvints driesvints changed the title Allow Fortify views to accept Responsable objects [1.x] Allow Fortify views to accept Responsable objects Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants