PROBLEM
Hello, long time ago I got 500 Internal Server Error when I use method PUT in angularjs (I'm trying to update list name), but still don't know how to fix it and make update work. Please help me.
ERROR
When I'm changed list name and hit enter in console shows error PUT http://localhost/anydo/anydocopy/anydocopy/public/lists/1 500 (Internal Server Error)
. I checked Network->Preview in google chrome and there shows TokenMismatchException in VerifyCsrfToken.php line 53:
. So anybody know where is problem?
CODE
routes.php
Route::group(['middleware' => 'cors'], function () {
Route::get('tasks', 'TasksController@index');
Route::get('lists', 'ListsController@index');
Route::get('lists/{id}', 'ListsController@show');
Route::post('lists', 'ListsController@store');
Route::put('lists/{id}', 'ListsController@update');
Route::post('lists/{id}', 'TasksController@store');
Route::delete('lists/{id}', 'ListsController@delete');
});
midleware cors.php
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;
}
}
controller
public function update($id, CreateListsRequest $request)
{
$response = Lists::findorfail($id)->update($request->all());
return Response($response, 201);
}
VerifyCsrToken.php (just because there show error)
class VerifyCsrfToken extends BaseVerifier
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
}
angular
$scope.updatel = function($event){
console.log($event.keyCode);
console.log($scope.editlist);
if ($event.keyCode == 13) {
var list = {
name: 'Test'
};
$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/anydo/anydocopy/anydocopy/public/lists'
})
.success(function (d) {
console.log(d);
$scope.listsdata = d;
});
})
.error(function () {
console.log(list);
console.log('false');
});
html
<div ng-repeat="lists in listsdata.lists">
<div id="DIV_24" close-on-outside-click="div.popup_information">
<button ng-click="lists.show = !lists.show" id="MORE_BUTTON">:</button>
<div class="popup_information" ng-show="lists.show">
<button id="DELETE_BUTTON" ng-click="del_list(lists)">X</button>
<button id="EDIT_BUTTON" ng-click="edbut.show = !edbut.show">E</button>
</div>
<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}}" />
<a href="#/{{lists.id}}">
<div id="DIV_25">
<label class="test" style="font-weight: normal" ng-show="!edbut.show" close-on-outside-click="test">{{lists.name}} </label>
</div>
<div id="DIV_26">
</div>
</a>
</div>
</div>
I know that mby too much code, but I don't understand how to fix this error and where I did mistake, so I just give you all code I'm working with. If need any other code, please ask in comments.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire