如果要始终为模型执行此转换,则可以将以下访问器方法添加到模型类中:
public function getNumbertemplateAttribute() {
return str_replace('x', '-', $this->attributes['numbertemplate']);
}
现在,每次访问$ customerCallPlan-> numbertemplate时,您都将获得转换后的字符串。
否则,只需在获取数据时转换列即可:
$plans = $callPlans->get()->map(function($plan) {
$plan->numbertemplate = str_replace('x', '-', $plan->numbertemplate);
return $plan;
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句