dacatadmin框架,form表单使用tree字段,新增提交时候报错:Array to string conversion {"exception":"[object] (ErrorException(code: 0): Array to string conversion

dacatadmin框架,form表单使用tree字段,新增提交时候报错:Array to string conversion {“exception”:”[object] (ErrorException(code: 0): Array to string conversion

form表单代码如下:

dacatadmin框架,form表单使用tree字段,新增提交时候报错:Array to string conversion {"exception":"[object] (ErrorException(code: 0): Array to string conversion

附言 1  ·  9个月前

尝试过只保留tree提交保存不行,如果屏蔽掉tree结构提交保存成功,可以定位是tree的值有问题

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

class CaseMusic extends Model {

//自动设置转换
//protected $casts = [
//    "tree" => "array",
//];

//手动设置
public function setImagesAttribute($val){
    $this->attributes['tree'] = json_encode($val);
}
//手动转换
public function getImagesAttribute($val)
{
    return json_decode($val, true);
}

}

9个月前 评论
讨论数量: 2

这个错误提示不是很清楚了吗。数组转字符串了。saving里把数组转为字符串在提交

9个月前 评论

class CaseMusic extends Model {

//自动设置转换
//protected $casts = [
//    "tree" => "array",
//];

//手动设置
public function setImagesAttribute($val){
    $this->attributes['tree'] = json_encode($val);
}
//手动转换
public function getImagesAttribute($val)
{
    return json_decode($val, true);
}

}

9个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!