我试图从数据库中获取数据,然后以输入形式显示数据作为默认值。我正在使用angularjs $http get method
来检索数据但失败了。
我的laravel路线
Route::group(array('prefix' => 'api', 'before' => 'csrf'), function() {
Route::get('student', function() {
$name = Student::where('name')->first();
return Response::json($name);
});
}
AngularJS
.controller('syncApiCtrl', function ($scope, $timeout, Module, $http) {
$http.get('api/student').success(function(data) {
$scope.name = data;
console.log(data);
});
...
我想从学生表中获取名称,但结果返回给我的是类似的
结果
<!DOCTYPE html><!--[if lt IE 7]> <html lang="en" class="no-js lt-ie9 lt-ie8 lt-ie7">
Student::where('name')->first();
不正确。如果要检索第一个学生的名称,请执行Student::first()->name;
,但如果数据库表为空,则认为Student::first()
可以为null。
我希望这能帮到您:
Route::prefix('api')->group(function () {
Route::get('student', function() {
$name = Student::first()->name;
return Response::json($name);
});
});