在Laravel Nova(v1.0.3)中,有几种方法可以对资源字段的可见性进行细粒度控制(canSee,showOnDetail等).我找不到任何控制字段是否可编辑的方法.如何显示字段,但阻止用户编辑它(使其只读)?
例如,我想显示"Created At"字段,但我不希望用户能够更改它.
Mat*_*att 10
此功能已在v1.1.4(2018年10月1日)中添加.
用法示例:
Text:: make('SomethingImportant')
->withMeta(['extraAttributes' => [
'readonly' => true
]]),
Run Code Online (Sandbox Code Playgroud)
从 Nova 开始,>2.0您可以使用带有回调的 readonly 方法并检查资源:
Text::make("Read Only on Update")
->readonly(function() {
return $this->resource->id ? true : false;
}),
Run Code Online (Sandbox Code Playgroud)
甚至更好:
Text::make("Read Only on Update")
->readonly(function() {
return $this->resource->exists;
}),
Run Code Online (Sandbox Code Playgroud)
小智 5
As of v2.0.1, readonly() is native and accepts a callback, closure or boolean and can simply be called as:
Text::make('Name')->readonly(true)
Run Code Online (Sandbox Code Playgroud)
This may have been added prior to this version but the changelog does not specify if this is the case.
| 归档时间: |
|
| 查看次数: |
5676 次 |
| 最近记录: |