Skip to content

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
@taylorotwell taylorotwell merged commit bfcc012 into laravel:1.x Oct 2, 2020
@claudiodekker claudiodekker deleted the fortify-view-allow-responsable branch October 2, 2020 20:00
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