问题
我正在尝试使用Angular更新列表名称。我需要使用哪种方法?放?在我做PUT时它显示405错误方法不允许,所以我做错了什么?
我的代码
角
$scope.updatel = function($event){
console.log($event.keyCode);
if ($event.keyCode == 13) {
var list = {
name: $scope.editlist
};
$scope.editlist = '';
$http({
method: 'PUT',
url: 'http://localhost/anydo/anydocopy/anydocopy/public/lists/1',
data: list
})
.success(function () {
console.log('true');
$http({
method: 'GET',
url: 'http://localhost/anydocopy/public/lists'
})
.success(function (d) {
console.log(d);
$scope.listsdata = d;
});
})
.error(function () {
console.log('false');
});
}};
Laravel路线
Route::put('lists/{id}', 'ListsController@update');
Laravel控制器
public function update($id, CreateListsRequest $request)
{
$response['lists'] = Lists::findorfail($id)->update($request->all());
return Response($response, 201);
}
Laravel中间件
class Cors
{
public function handle($request, Closure $next)
{
$response = $next($request);
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set(
'Access-Control-Allow-Headers',
'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, x-xsrf-token, X-Requested-With'
);
$response->headers->set('Access-Control-Allow-Credentials', 'true');
$response->headers->set('Access-Control-Allow-Methods', '*');
return $response;
}
}
HTML
<input type="text" id="edit" ng-model="editlist" ng-show="edbut.show" ng-keydown="updatel($event)" onkeydown="hideshow(document.getElementById('edit'))" class="form-control" style="font:24px bold;" value="{{lists.name}}" />
EDITED
现在我有工作网址,是的,这是错误的。目前PUT方法仍然不起作用,并显示500内部服务器错误。怎么了?似乎错误与TokenMismatchException in VerifyCsrfToken.php line 53: