Seeders:
class CouponTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$coupons = (array)factory(\App\Coupon::class,10)->make();
Log::info('Created coupons.. ', $coupons);
}
}
class CompanyTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$companies = (array)factory(\App\Company::class,10)->make();
Log::info('Company users.. ', $companies);
}
}
class CustomerTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$customers = (array)factory(\App\Customer::class,10)->make();
Log::info('Created customers.. ', $customers);
}
}
class UserTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$users = (array)factory(User::class,10)->make();
Log::info('Created users.. ', $users);
}
}
class DBSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$classes = [\App\Company::class,\App\Customer::class,\App\Coupon::class,\App\Employee::class,\App\User::class];
$this->call($classes);
}
}
After i run php artisan db:seed --class=DBSeeder
I got the error after Seeding: App\Company:
BadMethodCallException : Method Illuminate\Database\Query\Builder::setContainer does not exist.
Whole trace :
Exception trace:
1 Illuminate\Database\Query\Builder::__call("setContainer") /Applications/XAMPP/xamppfiles/htdocs/sites/FakeProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1288
2 Illuminate\Database\Eloquent\Builder::__call("setContainer") /Applications/XAMPP/xamppfiles/htdocs/sites/FakeProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1511
Factories:
$factory->define(Company::class, function (Faker $faker) {
return [
"company_id"=>$faker->randomNumber(3000),
"logo"=>$faker->unique()->company
];
});
$factory->define(Coupon::class, function (Faker $faker) {
$types = ['Food','Travelling','Camping','Sport','Restaurants','Health'];
return [
"coupon_id"=>$faker->unique()->randomNumber(2000),
"title"=>$faker->unique()->randomLetter,
'amount'=>rand(1,50),
'price'=>(double)rand(1,100),
'type'=>array_rand($types),
'created_at'=>\Carbon\Carbon::now(),
'expired_at'=>\Carbon\Carbon::create(rand(2018,2020),rand(1,12),rand(1,31))
];
});
$factory->define(Customer::class, function (Faker $faker) {
return [
'customer_id'=>$faker->unique()->randomNumber(1000),
'first_name'=>$faker->name,
'last_name'=>$faker->name,
'nickname'=>$faker->unique()->userName,
'email'=>$faker->unique()->safeEmail,
'password'=>$faker->unique()->password
];
});
$factory->define(Employee::class, function (Faker $faker) {
return [
'employee_id'=>$faker->unique()->randomNumber(1000),
'first_name'=>$faker->name,
'last_name'=>$faker->name,
'nickname'=>$faker->unique()->userName,
'email'=>$faker->unique()->safeEmail,
'password'=>$faker->unique()->password
];
});
$factory->define(App\User::class, function (Faker $faker) {
return [
'user_nickname' => $faker->unique()->name,
'email' => $faker->unique()->safeEmail,
'password' => crypt(rand(1,1000),'plmaks'),
'remember_token' => str_random(10),
'id'=>$faker->unique()->randomNumber(3000),
'created_at'=>Carbon::now()->format('Y-m-d H:i:s'),
'updated_at'=>Carbon::now()->format('Y-m-d H:i:s')
];
});