【发布时间】:2021-11-25 22:36:07
【问题描述】:
我有一些标准的单个复选框,它们定义了一个特定的布尔值,即 is_active
<label class="form-check-label text-google">
<input type="checkbox" name="is_active" id="is_active" value="1" class="form-check-input"
@if (old('is_active') == '1' || (empty(old()) && $doctor->is_active == 1)) checked @endif>
{{ __('Doctor activated') }}
<i class="input-helper"></i>
</label>
当将它发送到我的控制器时,请求通过自定义请求类运行,我目前在其中执行以下操作。主要是更新方式,取消选中的复选框会在数据库中更新。
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$this->request->set("is_active", $this->request->has("is_active"));
return [ ...
我还将模型中的 is_active 属性转换为布尔值。 这里的最佳做法是什么?我找不到任何能引导我走向正确方向的东西...
提前致谢。
【问题讨论】:
-
你的问题不是很清楚。就我所见,您将表单的
is_active属性设置为1,然后您想在验证之前在Request 对象中覆盖此值,这是您正在尝试的吗? -
是的,这就是我想要实现的目标
标签: laravel eloquent request laravel-8