Query laravel 5.6

0

Hi, I'm doing what I tried to do something half complex that does not work out for me, it's the following: I have 3 tables:

  • users: the table that comes by default in laravel
  • payment_type: I show the types of payments
  • payment_users: I get the payment type id and the id of users

queries I do to know which one is selected:

 public function index($id)
{
    $pago = DB::table('tipo_pagos')->get();

    $paus = DB::table('pago_users as pu')
        ->where('pu.idvendedor', $id)
        ->join('tipo_pagos as tp', 'pu.idtipo_pago', '=', 'tp.idtipo_pago')
        ->get();
    return view('reserva.tipo-pago', compact('pago','paus', 'id'));
}

Well now I want to show the types of payments selected in the view "reservation.type-payment"

 <div class="container">
    <h2>Tipos de Pagos</h2>
</div>
<div class="container">
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
        <h4>Selecionar tipo de pago</h4>
        {!! Form::open(array('route' => 'tipo.pago.update', 'id'=>'form' ,'method'=>'POST','autocomplete' => 'off')) !!}
        {{Form::token()}}
            @foreach($pago as $pa)
                <div class="form-check">
                    <input type="checkbox" class="form-check-input" value="{{$pa->idtipo_pago}}">
                    <label class="form-check-label" for="exampleCheck1">{{$pa->nombre}}</label>
                </div>
            @endforeach
        <input type="hidden" value="{{$id}}" name="iduser">
        {!!Form::close()!!}
    </div>
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
        <h4>Pagos seleccionados</h4>
        @foreach($paus as $pa)
            <div class="form-check">
                <input checked type="checkbox" disabled class="form-check-input" value="{{$pa->idtipo_pago}}">
                <label class="form-check-label" for="exampleCheck1">{{$pa->nombre}}</label>
            </div>
        @endforeach
    </div>

    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <br>
        <button form="form" class="btn btn-primary" type="submit">Aplicar</button>
        <button form="form" class="btn btn-danger" type="reset">Calcelar</button>
    </div>
</div>

Well now I would like to know how I can do to mark the inputs on the left side, that is, those that are selected to be marked, to be able to desaserme from the column on the right side

    
asked by Juan Jose 13.05.2018 в 00:52
source

1 answer

1

You can try it in the following way, I have not tried it but I think it should work:

<div class="container">
    <h2>Tipos de Pagos</h2>
</div>
<div class="container">
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
        <h4>Selecionar tipo de pago</h4>
        {!! Form::open(array('route' => 'tipo.pago.update', 'id'=>'form' ,'method'=>'POST','autocomplete' => 'off')) !!}
        {{Form::token()}}
            @foreach($pago as $pa)
                <div class="form-check">
                    <input type="checkbox" {{ $paus->search(function($item, $key) use ($pa){ return $item->nombre == $pa->nombre; }) !== false ? "checked" : "" }} class="form-check-input" value="{{$pa->idtipo_pago}}">
                    <label class="form-check-label" for="exampleCheck1">{{$pa->nombre}}</label>
                </div>
            @endforeach
        <input type="hidden" value="{{$id}}" name="iduser">
        {!!Form::close()!!}
    </div>

    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <br>
        <button form="form" class="btn btn-primary" type="submit">Aplicar</button>
        <button form="form" class="btn btn-danger" type="reset">Calcelar</button>
    </div>
</div>
    
answered by 13.05.2018 в 04:11