模型:无法更新数据库中的值
我有这个函数来更新数据库值,但其中一条语句不起作用。我创建了一个与名为 ventas
的表的关系,但是,它并没有将其值更新为 NULL。这是我的代码:
public function cambiarEstatusFactura( Request $request){
try{
\DB::beginTransaction();
$factura = FacturaVenta::with('venta')->where( 'id' , $request->id )->first();
// dd('Esto : ' , $factura->venta->factura_uuid);
if( $factura->estatus == 'Timbrada' ){
$factura->estatus = 'Cancelada';
$factura->uuid = NULL;
$factura->venta->factura_uuid = NULL;
$factura->save();
}
\DB::commit();
}catch (Exception $e){
\Alert::error($e->getMessage())->flash();
return redirect('admin/finanzas/factura/venta');
}
}
不起作用的语句是:
$factura->venta->factura_uuid = NULL;
虽然其他语句无缝工作,但这似乎有问题,但我没有收到任何错误消息。
变量 $factura
包含 FacturaVenta 模型,关系 venta
从表 ventas
中引入模型,这就是我尝试通过 访问它的原因>$factura->venta
和注释的 dd('Esto : ' , $factura->venta->factura_uuid);
代码中的值正确,这意味着它正确指向正确的表,但没有更新为 NULL
。
我只想将值从它所具有的任何值更新为NULL
。
你能帮我一下吗?
I have this function to update the DB values, but one of the statements is not working. I created a relation to the table called ventas
, however, it is not updating it´s value to NULL. This is my code:
public function cambiarEstatusFactura( Request $request){
try{
\DB::beginTransaction();
$factura = FacturaVenta::with('venta')->where( 'id' , $request->id )->first();
// dd('Esto : ' , $factura->venta->factura_uuid);
if( $factura->estatus == 'Timbrada' ){
$factura->estatus = 'Cancelada';
$factura->uuid = NULL;
$factura->venta->factura_uuid = NULL;
$factura->save();
}
\DB::commit();
}catch (Exception $e){
\Alert::error($e->getMessage())->flash();
return redirect('admin/finanzas/factura/venta');
}
}
The statement that is not working is:
$factura->venta->factura_uuid = NULL;
Though the other statements work seamlessly, this seems to have issues but I do not get any error messages.
Variable $factura
contains FacturaVenta model and the relation venta
brings the model from the table ventas
, that's why I try to access to it via $factura->venta
and the commented dd('Esto : ' , $factura->venta->factura_uuid);
in the code brings the value correctly, that means that it's pointing correctly to the correct table but it's not being updated to NULL
.
I just want to update the value from whatever it has to NULL
.
Could you help me please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论