I have a method or function where I update and create if a value exists
public function createupdatepayment(PaymentTypeFormRequest $request)
{
$rut = Auth::user()->rut;
$paymentcondition = PendingDocument::updateOrCreate(
['docentry' => $request->DocEntry],
['tipodecobro' => $request->tipodecobro,
'banco' => $request->banco
]
);
return view('frontend.billing.pending');
}
It will be the case that if I have a payment type that has a confirming value, I will save the value of the bank, otherwise, if it is different, I will store a NUll in the table field
'banco' => $request->banco
Something like this occurs to me but I get confused in how I pass the values, the idea is that the bank that comes is stored only if Confirming arrives, otherwise a null value is stored
'banco' => $request->tipodecobro ? Confirming ($request->banco) : null,
This is my edit form in the front from where the confirming comes in a value of the option
<form method="POST" action="{{ route("frontend.billing.update")}}">
<input type="text" class="form-control" name="DocEntry" id="DocEntry" value="{{ request()->DocEntry }}" hidden>
<div class="form-group">
<label class="required" for="tipodecobro">Cambiar tipo de cobro</label>
<select class="form-control select2" name="tipodecobro" id="tipodecobro" required>
<option value="Vencimiento en 30 días">Vencimiento en 30 días</option>
<option value="Factoring" id="topic">Factoring</option>
<option value="Confirming">Confirming</option>
</select>
@if($errors->has('name'))
<div class="invalid-feedback">
{{ $errors->first('name') }}
</div>
@endif
</div>
<div class="form-group d-none" id="bancos">
<label class="required" for="banco">Seleccione un banco</label>
<select class="form-control select2" name="banco" id="banco">
<option value="">Seleccione un Banco</option>
@foreach($bancos as $banco)
<option value="{{$banco->name}}">{{$banco->name}}</option>
@endforeach
</select>
@if($errors->has('name'))
<div class="invalid-feedback">
{{ $errors->first('name') }}
</div>
@endif
</div>
<div class="form-group d-flex mt-5">
<a href="{{route('frontend.billing.pending')}}" class="btn button button--danger font-weight-bold mr-auto">
Cancelar
</a>
<input type="submit" value="Guardar" class="btn button button--primary button--large font-weight-bold" href="{{route('frontend.billing.pending')}}">
</div>
@csrf
</form>
ternary operations must go between parentheses and when you compare data from a form you have to call them as members of the request.
when you access the input/members it is done as follows:
Then the evaluation would be as follows, value of the select vs a Literal (string):
then in your array:
note: I do not recommend doing ternary analysis within the construction of arrays or objects... they can mess it up when you go to debug.
Another important piece of information for you to do debugging and step-by-step validations you can use
dd()
:Additional how ternary comparisons are expressed:
Ternary operation in a line as follows:
Ternary operation in several lines as it is:
It also supports nesting 2 or more ternary operations:
Note: But at this point I would recommend using a
witch
If Confirming is a function that returns the type of payment, the sentence would be like this
The first field of the ternary operator is the condition, the second is the action if the condition is true, and the third is the action if the condition is false.