Skip to content

Instantly share code, notes, and snippets.

@arielcr
Created September 8, 2014 16:52
Show Gist options
  • Save arielcr/85433018bdccbab75b45 to your computer and use it in GitHub Desktop.
Save arielcr/85433018bdccbab75b45 to your computer and use it in GitHub Desktop.
Laravel filter to allowOrigin
Route::filter('allowOrigin', function($route, $request, $response)
{
$response->header('access-control-allow-origin','*');
});
@Maykonn
Copy link

Maykonn commented Mar 12, 2015

I configured my routes as following code:

Route::group(['after' => 'allowOrigin'], function() use () {
    Route::post('/users', function() {
         // ...
    });
});

But, the header not has Access-Control-Allow-Origin. Whats happens?

@Maykonn
Copy link

Maykonn commented Mar 12, 2015

Obvious, is necessary to put the routes into a group:

Route::group(['after' => 'allowOrigin'], function() {
    Route::post('/users', function() {
         // ...
    });
});

And now works!

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