dimanche 20 septembre 2015

how to update using angular

PROBLEM

Hello, I'm trying to update list name using angular.. Which method I need to use? PUT? At the moment when I do PUT shows 405 error method not allowed, so what i'm doing wrong?

MY CODE

Angular

  $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/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 rout

Route::put('lists/{id}', 'ListsController@update');

Laravel controller

public function update($id, CreateListsRequest $request)
{
    $response['lists'] = Lists::findorfail($id)->update($request->all());

    return Response($response, 201);
}

Laravel midleware

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}}" />



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire