连接Laravel和Angulars时发生内部服务器错误

时间:2019-02-10 02:12:19

标签: php angularjs laravel

我想开发简单的前端AngularJS和后端Laravel。我不知道为什么我的AngularJS路由未与Laravel路由连接。它一直被称为GET http://localhost/api/todos内部服务器错误。

Hello.php

<html>
<head>
    <title>Laravel + Angularjs</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
</head>
<body ng-App>
    <div id="todos" ng-controller="Todoctrl">
    <h3 class="page-header">Todos<small ng-if="remaining()">{{remaining()}} remaining</small>
    </h3>
    <ul  class="unstyled">
        <li ng-repeat="todo in todos">
            <input type="checkbox" ng-model="todo.done">
            {{todo.text}}
        </li>
    </ul>
    </div>
</script>
    <script src="js/app.js">
</script>
</body>
</html>

Todo.php(模型)

<?php

    namespace App;

    use Illuminate\Database\Eloquent\Model;

    class Todo extends Model
    {
        protected $guarderd = [];

    }

api.php

  Route::middleware('auth:api')->get('/user', function (Request $request) {
        return $request->user();
    });
    Route::get('/todos',function(Request $request){
        return $request->user();
    });

app.js
function Todoctrl($scope,$http){
    $http.get('api/todos').success(function(todos){
        $scope.todos = todos;
    });
    $scope.remaining = function(){
        var count = 0;
        angular.forEach($scope.todos,function(todo){
            count == todo.done ? 0 : 1;
        });

    }
}

0 个答案:

没有答案