Errors with Put and Delete Methods - MethodNotAllowedHttpException - Laravel and Angular

0

Hello, follow my fight with angular and laravel.

Now I'm having trouble with the put and delete methods, I did nothing more than I had before in my code, I'm just adding more models - where I copy the previous code and dumb the names.

But when I try to edit or delete a record, I get this error.

MethodNotAllowedHttpException laravel

And by the console

  

DELETE link 500 (Internal Server Error)   (anonymous) @ angular.js: 11881   sendReq @ angular.js: 11642   serverRequest @ angular.js: 11352   processQueue @ angular.js: 16170   (anonymous) @ angular.js: 16186   $ eval @ angular.js: 17444   $ digest @ angular.js: 17257   $ apply @ angular.js: 17552   (anonymous) @ angular.js: 25627   dispatch @ app.js: 3   g.handle @ app.js: 3

I have tried some things of similar errors that I saw here in the forum, but nothing so far, and I do not know what could be, because my code had been working normally.

I do not know where the error might be so I'll post some parts, if need be, ask for more.

PS: The only difference now for the previous models is that it has an N / N relationship, but the previous model that is 1 / N also started giving error.

Sincerely.

namespace confin;

use Illuminate\Database\Eloquent\Model;

class Empresa extends Model
{

    public function processo()
    {
        return $this->belongsToMany('confin\Processo','empresa_processo');
    }


}

    class Processo extends Model {

    public function convites()

    {

        return $this->hasOne('confin\Convites');
    }


    public function empresa()
    {
        return $this->belongsToMany('confin\Empresa','empresa_processo');
    }

}


<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
     <div class="modal-content">
        <div class="modal-header">
           <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
           <h4 class="modal-title" id="myModalLabel">Cadastro de Número de processo</h4>
        </div>
        <div class="modal-body">

            <div class="form-group">
              <input type="hidden" class="form-control" ng-model="processo.ano" >
              <label>Ano:</label>
              <input type="text" class="form-control" ng-model="processo.ano">
           </div>

           <div class="form-group">
              <label>Nº. Processo:</label>
              <input type="text" class="form-control" ng-model="processo.numero">
           </div>

           <label>Descrição:</label>
           <div class="form-group">
              <textarea  class="form-control" ng-model="processo.descricao"rows="10" cols="500"></textarea>
           </div>

        </div>

        <div class="modal-footer">
           <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="processo = {}">Cancelar</button>
           <button type="button" class="btn btn-primary" ng-click="salvar()">Salvar</button>
        </div>
     </div>
  </div>
</div>



app.factory('processoService',function($http) {
    return {
        lista: function(){
            return $http.get('/processos/lista');
        },
        cadastra: function(data){
            return $http.post('/processos/cadastra', data);
        },
        edita: function(data){
            var id = data.id;
            delete data.id;
            return $http.put('/processos/edita/'+id, data);
        },
        exclui: function(id){
            return $http.delete('/processos/exclui/'+id)
        }
    }
});



// Controller
app.controller('processosController', function($scope, processoService, empresaService) {
    $scope.listar = function(){
        processoService.lista().success(function(data){
            $scope.processos = data;
        });

        // ordenar
        $scope.ordenar = function(keyname){
        $scope.sortKey = keyname;
        $scope.reverse = !$scope.reverse;
        };
    }


    $scope.editar = function(data){
        $scope.processo = data;
        $('#myModal').modal('show');
    }

    $scope.salvar = function(){
        alert(processo.id);
        if($scope.processo.id){
            processoService.edita($scope.processo).success(function(res){
                $scope.listar();
                $('#myModal').modal('hide');
            });
        }else{
            processoService.cadastra($scope.processo).success(function(res){
                $scope.listar();
                $('#myModal').modal('hide');
            });
        }
    }

    $scope.excluir = function(data){
        if(confirm("Tem certeza que deseja excluir?")){
            processoService.exclui(data.id).success(function(res){
                $scope.listar();
            });
        }
    }
});




namespace confin\Http\Controllers;

use Illuminate\Http\Request;

use DB; // para usar a classe DB

class ProcessoController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    // Index
    public function index()
    {
        return view('processo');
    }

    // Listando processo
    public function lista()
    {
        return DB::table('processos')
            ->get();
    }


    // Cadastrando Processo
    public function novo(Request $request)
    {
        $data = sizeof($_POST) > 0 ? $_POST : json_decode($request->getContent(), true); // Pega o post ou o raw

        return DB::table('processos')
            ->insertGetId($data);
    }


    // Editando processo
    public function editar($id, Request $request){
        $data = sizeof($_POST) > 0 ? $_POST : json_decode($request->getContent(), true); // Pega o post ou o raw

        $res = DB::table('processos')
            ->where('id',$id)
            ->update($data);

        return ["status" => ($res)?'ok':'erro'];
    }


    // Excluindo Processo
    public function excluir($id)
    {
        $res = DB::table('processos')
            -> where('id',$id)
            -> delete();

        return ["status" => ($res)?'ok':'erro'];
    }
}

DELETE register / process / {id} confin \ Http \ Controllers \ ProcessController @ delete web, auth

PUT registration / process / {id} confin \ Http \ Controllers \ ProcessController @ web edit, auth

POST registration / processes confin \ Http \ Controllers \ ProcessController @ new web, auth

GET | HEAD | registration / processes confin \ Http \ Controllers \ ProcessController @ web list, auth

    
asked by anonymous 23.02.2017 / 17:28

1 answer

0

This is certainly problems with routes.

1st - Search in php artisan route:list if route empresas/exclui/{id} is defined and with DELETE method

2 - If the route :: resource / get / post / delete line of the Processes of your routes.php file is not set up for me to take a look at.

    
24.02.2017 / 13:32