Vue.js + Laravel Access-Control-Allow-Origin

Create Cors middleware

# php artisan make:middleware Cors
Middleware created successfully.


public function handle($request, Closure $next)
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');

app/Http/Kernel.php $routedMiddleware array add

'cors' => \App\Http\Middleware\Cors::class,


Route::group(['middleware' => 'cors'], function () {

Route::get('/v1/employees/{id?}', 'Employees@index');
Route::post('/v1/employees', 'Employees@store');
Route::post('/v1/employees/{id}', 'Employees@update');
Route::delete('/v1/employees/{id}', 'Employees@destroy');

Like what you read? Give Soon Wang a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.