Laravel 5 控制台文件路径错误

Laravel 5 file path error in console

我正在使用 Laravel 5 创建 Web 应用程序。

我想使用 AngularJS。 我在 views 目录中创建了一个名为 all-products.php 的文件,其中包含 JSON 格式的数据。

当我在 http.open() 中给出这个文件的路径时,它给出了一个错误 http://localhost/user/app/resources/views/all-products.php 404 (Not Found).

这是我的 JS 代码:

var app = angular.module("products", []);
    app.controller("productsController", function($scope, $http){
        $http.get("http://localhost/user/app/resources/views/all-products.php").success(function(response) {
            $scope.records = response.records;
        });
    });

请告诉我如何解决这个问题?

提前致谢。

您需要将文件放在 public 目录中,例如

http.get("http://localhost/all-products.json")

将是路径 public\all-product.json 中的文件(假设您的主页是 http://localhost)。

或者,如果文件是动态创建的,您需要创建一个路由,然后 return 使用 Response::json(['some data]);

从那里获取 .json 数据