我有一些种子文件使用了使用约定的数组:
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}}
这在我的localhost上工作正常,所以我不知道出了什么问题。谢谢你的帮助!
编辑(这是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。
答案 0 :(得分:0)
与HTTP服务器相比,命令行指向不同的PHP文件。
您需要与服务器主机通话并告诉他们您的命令行PHP版本是5.3.26,但您需要它至少为5.4。如果他们可以改变它,它取决于他们。
如果您无法更改命令行PHP版本 - 您可以使用此软件包通过Web执行artisan命令:
https://github.com/jn-Jones/web-artisan
http://forums.laravel.io/viewtopic.php?id=10334
或者另一种选择只是将数组从[]更改为array() - 并让它使用5.3