Get the id of a database column

0

I am trying to find the id of a sale in order to update the detail table Sale. This when that sale has already been charged.

I have a function in this way, in the sale table it looks for and updates the id of the sale but in its detail it does not generate it. How can I find out the id of the sale to update the detail table?

public function cobrar(Request $request, $id)
{
    $buscarPago = VentaUtp::findOrFail($id);
    $buscarPago->cantidadPagada="300";
    $buscarPago->update();


    $actualizarDetalle = DB::table('alumnopagosdet')
    ->select('idAlumnoCxC')
    ->where('idAlumnoCxC', '=', $id)
    ->get();


    $mytime = Carbon::now('America/Mexico_City');
    $venta->fecha_hora=$mytime->toDateTimeString();

    $actualizarPago = DetalleVentaUtp::findOrFail($detalle);
    $actualizarPago->fecha= $venta;
    $actualizarPago->caja=$request->get('caja');
    $actualizarPago->reciboCaja=$request->get('reciboCaja');
    $actualizarPago->anio=$request->get('anio');
    $actualizarPago->mes=$request->get('mes');
    $actualizarPago->cantidad=$buscarPago->cantidadPagada;
    $actualizarPago->update();

    return Redirect::to('utp/venta');


}
    
asked by Juan Antonio 21.06.2018 в 20:50
source

1 answer

0

the way you are receiving the data is wrong the get method is not used Here is a code correction I do not know what you are doing this consultation

$actualizarDetalle = DB::table('alumnopagosdet')
    ->select('idAlumnoCxC')
    ->where('idAlumnoCxC', '=', $id)
    ->get();

here is the example if you are going to send it by post method, the validation depends on the data that is sent or the type of characters

 <?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use Validator;
use Response;
use App\BarriosModel;
use App\AsistenciaModel;
use View;

class AsistenciaController extends Controller
{
    public function __construct(){
        $this->middleware('auth');
    }
    /**
    * @var array
    */
    protected $rules =
    [
                'caja' => 'required|min:2|max:255|regex:/^([0-9a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([0-9a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/',
                'reciboCaja' => 'required|min:1|max:99999999',
                'anio' => 'required|min:2|max:255|regex:/^([0-9a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([0-9a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/',
                'mes' => 'required|min:2|max:255|regex:/^([0-9a-zA-ZñÑáéíóúÁÉÍÓÚ_-])+((\s*)+([0-9a-zA-ZñÑáéíóúÁÉÍÓÚ_-]*)*)+$/',
    ];
public function update(Request $request, $id){
        $validator = Validator::make(Input::all(), $this->rules);
        if ($validator->fails()) {
            return Response::json(array('errors' => $validator->getMessageBag()->toArray()));
        } else {

                $buscarPago = VentaUtp::findOrFail($id);
                $buscarPago->cantidadPagada="300";
                $buscarPago->update();

                $actualizarPago = DetalleVentaUtp::findOrFail($id);

                $actualizarPago->fecha= $venta;
                $actualizarPago->caja=$request->caja;
                $actualizarPago->reciboCaja=$request->reciboCaja;
                $actualizarPago->anio=$request->anio;
                $actualizarPago->mes=$request->mes;
                $actualizarPago->cantidad=$buscarPago->cantidadPagada;


                $actualizarPago->save();
                return response()->json($actualizarPago);
        }
    }

?>
    
answered by 21.06.2018 в 21:35