I am using Laravel's updateOrCreate method and for one case I need to insert a value if it doesn't exist.
$newproduct = PendingDocument::updateOrCreate(
['docentry' => $docentry],
['documento' => $documento,
'cardname' => $cardname,
'doctotal' => $doctotal,
'totaldeuda' => $doctotal,
'tipodecobro' => 'Vencimiento en 30 días',
'deleted' => "ACTUALIZADO",
]
);
For this case I need to insert a value when the record does not exist, and insert tipocobro
the value into vencimiento en 30 dias
it now if this docentry exists in my database do not insert anything, skip this field, how should I change my code for this? Is it possible to put a conditional here? If so, how would the code be? I have tried with an if like this
if('tipodecobro' == null){'tipodecobro' => 'Vencimiento en 30 días'},
but this gives me an error...
What you have to do is make a one-line conditional with the code you have above, you should have something like this:
what this does is validate (with a single line if) if the variable $docentry is
null
the field it will haveVencimiento en 30 días
if not the field will remainnull
I hope I have helped you, regards.