laravel-5 - 筛选字段时出现“从空值创建默认对象”
问题描述
我正在尝试根据以特定字符串开头的用户名动态更改字段标签
public function filterFields($fields,$context = null)
{
$nager = WartaDataProfil::where('backend_users_id',$this->getBackendUserId())->pluck('nager');
if(Str::startsWith($nager[0],'GP')){
$fields->wil->label = "Sektor";
}
}
我有错误
从空值创建默认对象
从线
$fields->wil->label = "Sektor";
当我dd($fields->wil->label);
得到在 yaml 文件中定义的默认字符串时。
字段.yaml
fields:
nowarta:
label: 'No. Warta'
...
tanggal:
label: 'Tanggal'
...
batasno:
label: ''
...
type: section
tabs:
fields:
renung:
label: 'Renungan Mingguan'
span: full
type: section
tab: 'Renungan/Artikel'
renungan:
label: ''
...
type: repeater
...
minItems: '1'
maxItems: '1'
form:
fields:
judul:
label: 'Judul'
...
bacaan:
label: 'Bahan'
...
penulis:
label: 'Penulis'
...
isi:
label: Renungan
...
keb:
label: 'Kebaktian Umum'
span: full
type: section
tab: 'Kebaktian'
kebakti:
label: ''
span: full
type: partial
path: field_kebum
tab: 'Kebaktian'
kom:
label: 'Kebaktian Komisi'
span: left
type: section
tab: 'Kebaktian'
wil: <<< THIS FIELD <<<<<<<<<<<<<<<<<
label: 'Persekutuan Wilayah'
span: right
type: section
tab: 'Kebaktian'
Komisi:
label: ''
span: left
type: partial
path: field_kebkom
tab: 'Kebaktian'
pwil:
label: ''
span: right
type: partial
path: field_pwilayah
tab: 'Kebaktian'
希望这有助于解决我的问题..因为我在其他模型中使用相同的 filterField 并且它工作正常..
解决方案
推荐阅读
- python - Python PIL 模块:ModuleNotFoundError:没有名为“PIL”的模块
- python - 在 matplotlib 中,绘制数据的分组条
- javascript - Aws multipart 无法暂停(t.forEach 不是函数)Uppy
- c# - C# - 在地图上显示图钉时如何限制检索的数据
- c# - 对复合主键的两个引用中的共享属性
- php - 我无法制作文件资源管理器
- r - 无法在 jupyter 中为 r 内核安装 tidyverse 包
- python - Python pandas plot:使用两列生成一个y轴
- reactjs - 迁移到 Typescript 后,React 组件找不到 redux 存储道具和操作
- c# - 如何在 C# 中舍入当前时间