簡體   English   中英

Laravel Eloquent不會將模型保存到數據庫

[英]Laravel Eloquent doesn't save model to the database

我想雄辯地在數據庫上創建一條記錄,但它一直告訴我這個錯誤:

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

我已記錄要插入的數據:

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
)

它停在類型字段

我的表格列和類型:

'text_id' => INT,
'user_id' => INT,
'spots' => JSON,
'type' => VARCHAR(256),
'updated_at' => DATETIME
'created_at' => DATETIME

什么時候發生?

在模型中,您需要將type為JSON。

protected $casts = [
    'type' => 'json',
];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM