PHP解析错误:语法错误,意外T_OBJECT_OPERATOR,期待']'在第1行

时间:2017-04-19 19:22:50

标签: php laravel-5.4

我使用下面的语句在表格中输入数据'歌曲'在命令提示符下使用php artisan tinker,但它显示PHP Parse error: Syntax error, unexpected T_OBJECT_OPERATOR, expecting ']' on line 1

DB::table('songs')->insert(['title'->'Closer','artist'->'chainsmokers','created_at'->new DateTime,'updated_at'->new DateTime ]);

1 个答案:

答案 0 :(得分:2)

使用=>代替->

DB::table('songs')->insert([
    'title' => 'Closer',
    'artist' => 'chainsmokers',
    'created_at' => new DateTime,
    'updated_at' => new DateTime,
]);