我使用 bootstrap 表单从数组中的复选框值获取输入.

这是我的密码

<div class="form-group col-md-12">
    <div class="custom-control custom-checkbox custom-control-inline">
        <input type="checkbox" id="eduPrimary" name="education[]" 
        class="custom-control-input" value="primary" />
        <label class="custom-control-label" for="eduPrimary">primary</label>
    </div>
</div>
<div class="form-group col-md-12">
    <div class="custom-control custom-checkbox custom-control-inline">
        <input type="checkbox" id="eduSecondary" name="education[]" 
        class="custom-control-input" value="secondary" />
        <label class="custom-control-label" for="eduSecondary">secondary</label>
    </div>
</div>
<div class="form-group col-md-12">
    <div class="custom-control custom-checkbox custom-control-inline">
        <input type="checkbox" id="eduUniversity" name="education[]" 
        class="custom-control-input" value="university" />
        <label class="custom-control-label"for="eduUniversity">university</label>
    </div>
</div>

在后端,我使用laravel将值存储到数据库中,但在mysql中存储数组到字符串时出错.

public function store(Request $request,AdProfile $adprofile)
{
    $adprofile->education = $request->education[];
    $adprofile->save();
    return redirect()->route('adprofile.profilecomplete');
}

推荐答案

 print_r($request->education); //It is an array print

$str_json = json_encode($request->education); //array to json string conversion
echo  $str_json; // printing json string

print_r(json_decode($str_json)); //printing array after convert json string to array

exit; // exiting further execution to check resutls

Laravel相关问答推荐

Laravel本地化错误:"setlocale():参数#1($category)的类型必须是int,给定的是Illuminate\Http\Request"

Laravel AppServiceProvider 中的代码在通过 DeployHQ 部署时停止 Composer 和构建

spatie 包 laravel-tags 在迁移中没有 down() 函数是有原因的吗

Laravel 9 如何将 url 中的参数从一个控制器传递到另一个控制器?

如何获得每种类型的总和

Eloquent的条件过滤器

Laravel Eloquent,仅 Select 存在关系的行

如何监控 Laravel 队列是否正在运行?

.gitignore 不忽略文件夹

如何在 Laravel 中显示渲染时间/页面加载时间?

具有实时和 WebSockets 的 Angular2 + Laravel

Laravel:如何在没有数据库的情况下对用户进行身份验证

Laravel 生产问题 - 使用 Laravel 4.1.x 更新composer

中间件中的 Laravel 依赖注入

如何使用外部图像生成 html div 的 screenshot截图?

如何访问 Carbon 对象类型?

Laravel 规则和正则表达式 (OR) 运算符的问题

扩展模型 == 扩展 Eloquent?

Laravel / Eloquent内存泄漏重复检索相同的记录

如何在 Laravel 5.3 中获取当前的语言环境