1
Hello, follow my fight with angular and Laravel.
Now I’m having trouble with put and delete methods, I did nothing but what I had before in my code, I’m just adding more models - where I copy the previous code and change the names.
But while trying to edit or delete some record, I get this error
MethodNotAllowedHttpException in the Laravel 
And by the console
DELETE http://localhost:8000/business/excludes/1 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’ve tried some things similar errors I’ve seen here on the forum, but nothing so far, and I don’t know what could be, because my code was working normally.
I don’t know where the error might be so I’ll post some parts, if necessary request that I include more.
PS: the only difference now for previous models is that this one has an N/N relationship, but the previous model that is 1/N also started to give error.
Sincerely yours.
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">×</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 registration/process/{id} confin Http Controllers Processocontroller@delete web,auth
PUT registration/process/{id} confin Http Controllers Processocontroller@edit web,auth
POST registration/processes confin Http Controllers Processocontroller@new web,auth
GET|HEAD | register/processes confin Http Controllers Processocontroller@web list,auth
Ask your route file (I think what matters most about the question next to your process).
– Pliavi