Error 500 laravel on request ajax

0

Form:

    <div class="modal-body">
        <form name="frmEmployees" class="form-horizontal" novalidate="">
          <div class="form-group">
            <div class="col-sm-5">
              <label class="col-sm-3">Name</label>
              <input type="text" class="form-control has-error input-sm" id="name" value="@{{name}}" ng-model="product.name" ng-required="true">
            </div>
            <div class="col-sm-4">
              <label class="col-sm-3">Category</label>
              <select id="opcoesCat" class="form-control input-sm" ng-model="product.idcategory" 
            </div>
            <div class="col-sm-3">
              <label class="col-sm-3">Quantity</label>
              <input type="number" class="form-control has-error input-sm" id="quantity" value="@{{quantity}}" ng-model="product.quantity" ng-required="true">
              </div>
            <div class="col-sm-3">
              <label class="col-sm-3">Urgency</label>
              <input type="number" class="form-control has-error input-sm" id="idurgency" value="@{{idurgency}}" ng-model="product.idurgency" ng-required="true">
              </div> 
          </div>
        </form>
      </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-sm btn-primary" id="btn-save" ng-click="save(modalstate, id)" ng-disabled="frmEmployees.$invalid">Save changes</button>
        </div>

Controller php:

 public function store(Request $request)
{
    $need = new UrgentNeeds;
    $need->name = $request->input('name');
    $need->quantity = $request->input('quantity'); 
    $need->idcategory = $request->input('idcategory'); 
    $need->idurgency = $request->input('idurgency'); 
    $need->save();
    return 'Product record created' .$need->id;
}

Model:

class UrgentNeeds extends Model
{
    protected $table = 'urgentneeds';
    protected $fillable = array('id','name','quantity','idcategory','idurgency');
}

Javascript:

 $scope.save = function(modalstate, id) {
    var url = API_URL + "urgentNeeds";
    //alert("User: "+ $scope.product.idurgency); 
    //append employee id to the URL if the form is in edit mode
    if (modalstate === 'edit'){
        url += "/" + id;
    }

    console.log($scope.product);

    $http({
        method: 'POST',
        url: url,
        data: $.param($scope.product),
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).success(function(response) {
        console.log(response);
        location.reload();
    }).error(function(response) {
        console.log(response);
        alert('Erro!');
    });
}

I've tried to change the headers to this headers: { 'X-CSRF-TOKEN': $('meta[name=\'csrf-token\']').attr('content') }

and add the goal but still give me the error 500. Does anyone know of anything that is wrong?

    
asked by anonymous 10.05.2018 / 17:14

0 answers