Laravel 5 Laravel通过模型将json类型的列数据插入数据库

Laravel 5 Laravel通过模型将json类型的列数据插入数据库,laravel-5,eloquent,Laravel 5,Eloquent,嗨,我在迁移中使用了一个json列,并试图通过模型将值保存到数据中。这是我的迁移 Schema::create('notifications',函数(Blueprint$table){ $table->increments('id'); $table->json('title'); $table->json('message')->nullable(); $table->timestamps(); }); 这是我的模型代码 namespace-App\Models; 使用Illumb\Data

嗨,我在迁移中使用了一个json列,并试图通过模型将值保存到数据中。这是我的迁移

Schema::create('notifications',函数(Blueprint$table){
$table->increments('id');
$table->json('title');
$table->json('message')->nullable();
$table->timestamps();
});
这是我的模型代码

namespace-App\Models;
使用Illumb\Database\Elount\Model;
使用空间\可翻译\ HasTranslations;
使用Illumb\Database\Elount\Relations\BelongsTo;
使用Illumb\Database\Elount\Relations\HasOne;
类通知扩展了模型
{
使用翻译;
public$translateable=['title','message'];
受保护的$fillable=[
“标题”,“消息”
];
},
这是我的插入代码

$notification=新通知();
$notification_title=[
“en'=>“已创建请求”,
“it'=>“Richiesta creata”,
];
$notification\u title=json\u encode($notification\u title);
$notification_message=[
“en'=>“已创建请求”,
“it'=>“Richiesta creata”,
];
$notification_message=json_encode($notification_message);
$notification->title=$notification\u title;
$notification->message=$notification\u message;
$notification->save();
似乎json字段未正确保存。

json\u encode()
替换为:

类通知扩展了模型
{
受保护的$casts=[
“title”=>“array”,
'消息'=>'数组',
];
}
json\u encode()
替换为:

类通知扩展了模型
{
受保护的$casts=[
“title”=>“array”,
'消息'=>'数组',
];
}

数据是如何保存的?类似这样的-{“it”:“{“en\”:“Request created\”,“it\”:“Richi…很抱歉,但也很难复制:(很抱歉,我错过了您已经在应用
json\u encode()
。当您离开强制转换并删除
$notification\u title=json\u encode($notification\u title)时会发生什么
$notification\u message=json\u encode($notification\u message);
然后就可以了:)把它作为一个答案添加进去。谢谢,所以我已经把它添加到了我的答案中。数据是如何保存的?类似这样的-{“it”:“{”它:“{”创建的请求“,“it\”:“Richi…很抱歉,但它也很难复制:(很抱歉,我没有注意到您已经在应用
json\u encode()
。当您离开强制转换并删除
$notification\u title=json\u encode($notification\u title);
$notification\u message=json\u encode($notification\u message);
之后效果很好:)添加它作为答案。谢谢,所以我已经将它添加到我的答案中。