Skip to content

Instantly share code, notes, and snippets.

@ishukshin
Forked from ibourgeois/laravel-routes.php
Created December 20, 2015 16:04
Show Gist options
  • Save ishukshin/90c091366aea10e40437 to your computer and use it in GitHub Desktop.
Save ishukshin/90c091366aea10e40437 to your computer and use it in GitHub Desktop.
Bridging Laravel 5 and Lumen with Guzzle
<?php
// Obviously, you would build up the request somewhere other than a route...
Route::get('/api', function()
{
$client = new \GuzzleHttp\Client();
$response = $client->get('http://path/to/api');
return $response->getBody();
});
// Visiting '/api' would return "Hello World" from Lumen!
<?php
$app->get('/text', function()
{
return 'Hello World';
});
// You may need to enable CORS header if Laravel and Lumen are on separate servers!
$app->get('/json', function() use ($app)
{
return response()->json([
"foo" => 'bar'
])
->header('Access-Control-Allow-Origin', '*');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment