在Model中有时我们设置的获取器过多,但某个方法只想要个别的获取器属性,如果不处理,会把所有的获取器字段值返回给前端,这样显得数据特别臃肿
在查询的结果集进行处理
在app\Providers\AppServiceProvider.php
中boot()
方法加入:
return Collection::macro('setAppends', function (array $append = []) {
在Model中有时我们设置的获取器过多,但某个方法只想要个别的获取器属性,如果不处理,会把所有的获取器字段值返回给前端,这样显得数据特别臃肿
在查询的结果集进行处理
在app\Providers\AppServiceProvider.php
中boot()
方法加入:
return Collection::macro('setAppends', function (array $append = []) {