我有一些使用使用约定的数组的种子文件:
Array = [ ];
该数组使用方括号而不是圆括号。
我已经使用 phpinfo.php 文件检查了我的 php 版本,它正在读取:PHP Version 5.5.0
当我尝试在终端中运行 php artisan db:seed 时,出现以下错误:
php artisan db:seed
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"syntax error, unexpected '['","file":"\/nfs\/c09\/h04\/mnt\/139243\/domains\/*********.com\/app\/database\/seeds\/ArtistsTableSeeder.php","line":14}}
这在我的本地主机上运行良好,所以我不知道出了什么问题。谢谢您的帮助!
编辑(这里是 ArtistsTableSeeder.php):
<?php
class ArtistsTableSeeder extends Seeder {
public function run()
{
// Uncomment the below to wipe the table clean before populating
// DB::table('artists')->delete();
$artists = array(
);
$Artists = [
['stage_name' => 'Bob', 'city' => 'San Francisco', 'state' => 'CA', 'video_path' => 'http://www.youtube.com', 'image_path' => 'https://www.filepicker.io', 'soundcloud_profile' => 'https://soundcloud.com', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['stage_name' => 'Joe', 'city' => 'San Francisco', 'state' => 'CA', 'video_path' => 'http://www.youtube.com', 'image_path' => 'https://www.filepicker.io', 'soundcloud_profile' => 'https://soundcloud.com', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['stage_name' => 'George', 'city' => 'San Francisco', 'state' => 'CA', 'video_path' => 'http://www.youtube.com', 'image_path' => 'https://www.filepicker.io', 'soundcloud_profile' => 'https://soundcloud.com', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['stage_name' => 'Greg', 'city' => 'Seattle', 'state' => 'WA', 'video_path' => 'http://www.youtube.com', 'image_path' => 'https://www.filepicker.io', 'soundcloud_profile' => 'https://soundcloud.com', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['stage_name' => 'Leo', 'city' => 'San Francisco', 'state' => 'CA', 'video_path' => 'http://www.youtube.com', 'image_path' => 'https://www.filepicker.io', 'soundcloud_profile' => 'https://soundcloud.com', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['stage_name' => 'Nuck', 'city' => 'San Francisco', 'state' => 'CA', 'video_path' => 'http://www.youtube.com', 'image_path' => 'https://www.filepicker.io', 'soundcloud_profile' => 'https://soundcloud.com', 'created_at' => new DateTime, 'updated_at' => new DateTime]
];
// Uncomment the below to run the seeder
DB::table('artists')->insert($Artists);
}
}
回答编辑:对于其他有问题的人,在命令行中我必须使用 php-latest artisan db:seed。这确保我使用了最新版本的 php。