Laravel has a lot of magic under the hood that translates views returned from a controller into a response object. More specifically, the response object is an instance of Illuminate\Http\Response
, which extends from the Symfony response class.
To leverage this magic yourself, you can invoke it directly:
return Illuminate\Routing\Router::toResponse($request, $response);
return Route::toResponse($request, $response);
Here’s an Octane specific example:
Octane::route('GET', '/url', function($request) {
return Route::toResponse($request, view('...'));
});
Taking this approach would allow you to return anything you’re normally able to return (array, model, string, redirect, etc.) from a traditional route.
However, if you wanted something view specific, this would work as well:
use Illuminate\Http\Response;
Octane::route('GET', '/url', function() {
return new Response(view('...'));
});
Laravel's Response class knows how to convert renderables (which a view is an instance of) to a string.
The full blown Symfony specific implementation would look like this:
use Symfony\Component\HttpFoundation\Response;
Octane::route('GET', '/url', function() {
return new Response(view('...')->render());
});
Just to reiterate, all of these options would work. Use whichever solution you’re most comfortable with.
return view(...)
? – miken32RedirectResponse
to another route that can then send the view. (To be clear, I have no idea what Octane is, just making suggestions based on my Laravel experience.) – miken32