小编use*_*680的帖子

Laravel 5 + AngularJS跨域CORS

我到处寻找答案,但到目前为止还没有任何工作.堆栈上列出的所有解决方案都不足以证明是足够的.

我的laravel日志中没有任何错误形式,我只得到标准:

XMLHttpRequest cannot load http://api.domain.dev/post/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://domain.dev' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

Laravel控制器:

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Post;
use App\Tag;
use Illuminate\Http\Request;

class PostController extends Controller {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {

        $posts = Post::with('user', 'tags')->get();

        return response()->json($posts);
    }
}
Run Code Online (Sandbox Code Playgroud)

Laravel路线:

<?php

Route::resource('user', 'UserController');
Route::resource('post', 'PostController');
Route::get('post/tag/{tag}', 'PostController@postsWithTag');
Route::resource('tag', 'TagController');

Route::controllers([
    'auth' => 'Auth\AuthController', …
Run Code Online (Sandbox Code Playgroud)

cors angularjs laravel-5

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

angularjs ×1

cors ×1

laravel-5 ×1