[英]Laravel Eloquent doesn't save model to the database
I want to create a record on the database with eloquent but it keeps telling me this error : 我想雄辩地在数据库上创建一条记录,但它一直告诉我这个错误:
Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in /path/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 681 in /path/vendor/laravel/framework/src/Illuminate/Database/Grammar.php:135
I have logged data to be inserted : 我已记录要插入的数据:
array (
'text_id' => 12,
'user_id' => 2,
'spots' =>
array (
0 => 'a',
1 => 'd',
2 => 'd',
3 => 'r',
4 => 'g',
5 => 'h',
6 => 'w'
),
'type' => 'long',// error is on this field
)
it stops at the type field 它停在类型字段
My table columns & types : 我的表格列和类型:
'text_id' => INT,
'user_id' => INT,
'spots' => JSON,
'type' => VARCHAR(256),
'updated_at' => DATETIME
'created_at' => DATETIME
when does this happen ? 什么时候发生?
In your model you need to cast type
to JSON. 在模型中,您需要将
type
为JSON。
protected $casts = [
'type' => 'json',
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.