我想从模型中获取总计并传递给控制器,以便我可以按模型中计算出的变量值更新列。可能还是我应该使用带有隐藏值的输入?
代码:
protected static total = 0;
public function getRouteRateAttribute() {
$routes = array();
$array = \App\Waybill::with('route.route')->get();
foreach ($array as $object) {
foreach ($object->route as $route) {
$profit = $this->attributes['length'] * $route->route->profit;
$this -> total += $this->attributes['length'] * $route->route->profit;
$routes[] = array('name' => $route->route->name, 'profit' => $profit);
}
}
return $routes;
}
public function getTotalRateAttribute() {
return $this -> total;
}
public function getTotalMarginRateAttribute() {
$margin = \App\Business::select('margin')->firstOrFail();
return $this -> total * (1 - $margin->margin);
}
public function getMarginRateAttribute() {
$margin = \App\Business::select('margin')->firstOrFail();
return $this -> total * $margin -> margin;
}
我正在使用此属性查看发票。 发送运单后无法更新,因为管理员需要接受。 如果有人帮助我,我会很高兴。