2013-09-23 33 views
-1

我想我的種子DB按照說明上http://laravel.com/docs/migrations#database-seeding如何在Laravel種子?

class DatabaseSeeder extends Seeder { 

    public function run() 
    { 
     $this->call('UserTableSeeder'); 

     $this->command->info('User table seeded!'); 
    } 

} 

class UserTableSeeder extends Seeder { 

    public function run() 
    { 
     DB::table('users')->delete(); 

     User::create(array('email' => '[email protected]')); 
    } 

} 

我有點這個困惑。什麼是UserUser::create(array('email' => '[email protected]'));

+0

'E_NOT_WORKING'不是一個已知的PHP錯誤代碼。 –

回答

2

create方法在數據庫中插入一條記錄(Seeding是預填充數據庫的一種方式)。

它基本上調用名爲User模型,並通過將一個陣列使用在靜態方式Create()方法並返回表示與所傳遞的細節的用戶實體模型的一個實例。

+0

所以我需要先創建一個模型。我只是製作文件還是有作曲家/藝術家的方式開始?我是Laravel的新手。 – StackOverflowNewbie

+1

默認情況下,用戶模型包含在Laravel中。您可以手動創建自己的模型,或使用像L4生成器這樣的工匠工具:https://github.com/JeffreyWay/Laravel-4-Generators –