Php 返回有说服力的更改,而不更新laravel上的记录

Php 返回有说服力的更改,而不更新laravel上的记录,php,laravel,laravel-5,eloquent,Php,Laravel,Laravel 5,Eloquent,8项目 到目前为止一切都很好 我有这个密码 $item = $item_unit->getItem; $item->item_smallest_unit_cost = $item_unit->item_unit_coast_price; $item->item_smallest_unit_selling_price = $item_unit->item_unit_selling_price; return $item->get(); 如您所见,我需要更改项目

8项目 到目前为止一切都很好 我有这个密码

$item = $item_unit->getItem;
$item->item_smallest_unit_cost = $item_unit->item_unit_coast_price;
$item->item_smallest_unit_selling_price = $item_unit->item_unit_selling_price;
return $item->get();
如您所见,我需要更改
项目最小单位成本
项目最小单位销售价格
,然后返回项目而不更新原始数据库,但此代码返回带有旧项目
项目最小单位销售价格
项目最小单位成本的项目
我不想这样做

$item = $item_unit->getItem;
$item->item_smallest_unit_cost = $item_unit->item_unit_coast_price;
$item->item_smallest_unit_selling_price = $item_unit->item_unit_selling_price;
$item->update // i dont want to do this but i want to return the item new changes
return $item->get();

此处有任何帮助,请首先检查数据是否与以下内容不一致:

dd($item->item_smallest_unit_cost, $item_unit->item_unit_coast_price);
如果数据是预期结果,则需要保存更新的项目:

$item = $item_unit->getItem;
$item->item_smallest_unit_cost = $item_unit->item_unit_coast_price;
$item->item_smallest_unit_selling_price = $item_unit->item_unit_selling_price;
$item->save(); // You need that
return $item;
这应该行得通


您可以找到更多信息。

$item->item\u minimable\u unit\u cost=$item\u unit->item\u unit\u price;
$item->item\u最小单位销售价格=$item\u单位->item\u单位销售价格

而不是使用下面的

$item['item_smallest_unit_cost'] = $item_unit->item_unit_coast_price;
$item['item_smallest_unit_selling_price'] = $item_unit->item_unit_selling_price;

只是

return $item; 

可以
dd($item->item\u最小单位成本,$item\u单位->item\u单位价格)并提供您得到的信息?要么将其保存到数据库中,要么创建一个新变量来保存新数据。
return $item;