简体   繁体   中英

Laravel 4 DB seed issue

I am trying to create a database seed file. Here how is it:

class UsersSeeder extends DatabaseSeeder {

public function run()
{
    $users = [
        [
            'email' => 'mymail@mail.com',
            'password' => Hash::make('123456'),
            'name' => 'Admin'
        ]
     ];

    foreach ($users as $user) {
        User::create($user);
    }
}

}

When I run the artisan db:seed , I got this error message:

PHP Parse error: syntax error, unexpected '[' in E:\\www\\laravel4\\app\\datab ase\\seeds\\UsersSeeder.php

I don't see any error on my script. How can I solve it? Thank you.

You are probably using a PHP version below PHP 5.4.0 on your CLI (run php -v to be sure). Thus the short JSON-like array notation isn't supported. you should use array() instead (or upgrade).

$users = array (
      array  (
            'email' => 'mymail@mail.com',
            'password' => Hash::make('123456'),
            'name' => 'Admin'
        )
     );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM