gpt4 book ai didi

php - 更新 laravel Controller 中的复选框

转载 作者:行者123 更新时间:2023-12-02 07:23:18 24 4
gpt4 key购买 nike

我有这样的复选框:

<input {{isset($shop['private_post'])&&$shop['private_post']=='Yes' ? 'checked' : ''}} id="private_post" value="Yes" type="checkbox" name="private_post">

在 Controller 中:

$shop= shop::find($request['id']);
$shop->update($request->all());

在编辑模式下,当我选中复选框时,复选框正常工作,但当我取消选中复选框时,复选框不起作用。
我动态创建复选框,但无法使用此命令

If(!isset($request['private_post']))
$request['private_post']=0;
$shop= shop::find($request['id']);
$shop->update($request->all());

最佳答案

试试这个:

在 Blade 中

{!! Form::checkbox('private_post', '1', Input::old('private_post', 1)) !!}

在 Controller 中

$request['private_post'] = isset($request['private_post']) ? 1 : 0;

关于php - 更新 laravel Controller 中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37290629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com