I'm trying to save a record in a modal. But in that record there is a relationship. I have a code that supposedly mind does. When I register the information, I do not get an error, but it does not save my record.
The function is as follows: in the account index it shows me the account information among them the clients with their account details but it has a button where it says to credit the account since it is a credit. Then the function is that I go updating the balance of the account for the amount entered from the modal to pay.
These are the relationships of the tables:
In the index of the account I have a button that passes the id of the account to the modal:
<a data-target="#modal-abonar-{{$cue->idcuenta}}" data-toggle="modal" href="">
<button class="btn btn-success">
Abonar
</button>
</a>
This is the modal file (create) where I record the information:
<div class="modal fade modal-slide-in-right" role="dialog" aria-hidden="true" tabindex="-1" id="modal-abonar-{{$cue->idcuenta}}">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">x</span>
</button>
<h4 class="modal-title" id="myModalLabel">¿Deseas agregar un abono a la cuenta?</h4>
</div>
<div class="modal-body">
{!! Form::open(array('action'=>array('AbonoController@abonar',$cue->idcuenta), 'method'=>'POST','autocomplete'=>'off'))!!}
{{Form::token()}}
<div class="row">
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="cliente">
Cliente
</label>
<input class="form-control" name="cliente" value="{{$cue->cliente}}" disabled>
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="cantidad">
Cantidad
</label>
<input class="form-control" name="cantidad" placeholder="cantidad.." type="number" min="0">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="fecha">
Fecha
</label>
<input class="form-control" name="fecha" placeholder="fecha.." value="<?php echo date(" Y-m-d ");?>">
</div>
</div>
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12">
<div class="form-group">
<label for="observacion">
Observacion
</label>
<!--si el texto esta validado muestra el observacion ingresado-->
<input class="form-control" name="observacion" placeholder="observacion.." type="text">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
<button type="submit" class="btn btn-primary" data-dismiss="modal">Agregar</button>
</div>
</div>
</div>
{{Form::close()}}
</div>
In the subscription controller I have the function that registers the subscription (SubscriptionController):
public function abonar($id, Request $request)
{
//se busca el campo saldo del id correspondiente de la tabla cuenta
$sqlcuenta = Cuenta::findOrFail($id);
// $sqlcuenta = Cuenta::where('idcuenta', '=', $id);
$saldo = $sqlcuenta->saldo;
//se resta el saldo con la cantidad ingresada del formulario
$cantidad = $request->get('cantidad');
$saldo = $saldo - $cantidad;
//se actualiza el campo saldo de la cuenta con el id correspondiente
$cuentaSaldo =Cuenta::findOrFail($id);
// ->update(['saldo' => $saldo]);
$cuentaSaldo->saldo=$saldo;
$cuentaSaldo->save();
//-------SE BUSCA LA ULTIMA CUOTA PARA INCREMENTARLA-----
$noCuota = Abono::select('no_cuota')
->where('cuenta_id', '=', $id)
->orderBy('idabono', 'desc')
->limit(1)
->get();
if ($noCuota) {
$noCuota = $noCuota->no_cuota;
} else {
$noCuota = 0;
}
$noCuota = $noCuota + 1;
//---------------------SE INSERTA EL ABONO---------
$abono = new Abono();
$abono->cuenta_id = $request->get('cliente');
$abono->cantidad = $request->get('cantidad');
$abono->fecha = $request->get('fecha');
$abono->observacion = $request->get('observacion');
$abono->no_cuota=$noCuota;
$abono->saldo_abono=$cuentaSaldo;
return Redirect::to('cuentas/abono');
}
This is the route (web):
Route::post('cuentas/abono','AbonoController@abonar');