Simple Laravel 5 Seeding:Closure对象不能具有属性
问题描述:
I am trying to seed some files, yet I get:
[Error Exception] Closure object cannot have properties
Not sure what is wrong, since I do very basic seeding.
Here are my files:
all.php in tests/factories/all.php
$factory('App\User', [
'name' => $faker->name,
'email' => $faker->email,
'password' => password_hash('000400', PASSWORD_DEFAULT)
]);
This is the command I am using:
php artisan db:seed --class="UserTableSeeder"
This is my UserTableSeeder:
public function run()
{
// User::create([
// 'name' => 'Rainbow Warrior',
// 'email' => 'email@exmaple.org',
// 'password' => password_hash('123456', PASSWORD_DEFAULT)
// ]);
TestDummy::times(20)->create('App\User');
}
答
I had a typo inside my all.php that looked like this:
$factory('App\Comment', [
'user_id' => 'factory:App\User',
'question' => $factory->sentence,
'answer' => $factory->text
]);
If you look closely, you will notice, that instead of $faker, I wrote $factory. Well... fair enough.