Q:

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 ?

A:

In your model you need to cast type to JSON.
protected $casts = [
    'type' => 'json',
];

