Laravel 5.3 seed “Array to string conversion”


Trying to seed PHP array data into a JSON field (created through database table migration and specifying the JSON field type provided my Laravel 5.3 and MySQL 5.7.14)

The error

Array to string conversion (SQL insert into

The seed array


I’ve tried converting the json field type to text and then running it again with no luck (I also set the model set/get to handle json_encode/decode). This seems to work. You need to use create instead of Insert.
Then run the seed command:
Also don’t forget to add the casting into your model.
    protected $casts = [
        ‘enquiry_types’ => ‘json’

Sam Deering

Sam Deering is a web developer from England (currently living in Australia). In his spare time he enjoys coding, playing chess, reading and investing.

Leave a Reply

Your email address will not be published. Required fields are marked *