Remove hard-coded company_id in factories and update seeders

This commit is contained in:
Marcus Moore 2023-03-15 14:12:34 -07:00
parent fb789eb048
commit b944945377
No known key found for this signature in database
5 changed files with 29 additions and 12 deletions

View file

@ -59,7 +59,6 @@ class ComponentFactory extends Factory
'qty' => 10,
'min_amt' => 2,
'location_id' => 3,
'company_id' => 2,
];
});
}

View file

@ -3,6 +3,7 @@
namespace Database\Factories;
use App\Models\Category;
use App\Models\Company;
use App\Models\Manufacturer;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
@ -42,6 +43,7 @@ class ConsumableFactory extends Factory
'purchase_cost' => $this->faker->randomFloat(2, 1, 50),
'qty' => $this->faker->numberBetween(5, 10),
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
'company_id' => Company::factory(),
];
}
@ -58,7 +60,6 @@ class ConsumableFactory extends Factory
},
'qty' => 10,
'min_amt' => 2,
'company_id' => 3,
];
});
}

View file

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\Company;
use Illuminate\Database\Eloquent\Factories\Factory;
use \Auth;
@ -18,7 +19,7 @@ class UserFactory extends Factory
'activated' => 1,
'address' => $this->faker->address(),
'city' => $this->faker->city(),
'company_id' => rand(1, 4),
'company_id' => Company::factory(),
'country' => $this->faker->country(),
'department_id' => rand(1, 6),
'email' => $this->faker->safeEmail,

View file

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Models\Company;
use App\Models\Component;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
@ -12,9 +13,16 @@ class ComponentSeeder extends Seeder
{
Component::truncate();
DB::table('components_assets')->truncate();
Component::factory()->count(1)->ramCrucial4()->create(); // 1
Component::factory()->count(1)->ramCrucial8()->create(); // 1
Component::factory()->count(1)->ssdCrucial120()->create(); // 1
Component::factory()->count(1)->ssdCrucial240()->create(); // 1
if (! Company::count()) {
$this->call(CompanySeeder::class);
}
$companyIds = Company::all()->pluck('id');
Component::factory()->ramCrucial4()->create(['company_id' => $companyIds->random()]);
Component::factory()->ramCrucial8()->create(['company_id' => $companyIds->random()]);
Component::factory()->ssdCrucial120()->create(['company_id' => $companyIds->random()]);
Component::factory()->ssdCrucial240()->create(['company_id' => $companyIds->random()]);
}
}

View file

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Models\Company;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
@ -17,11 +18,18 @@ class UserSeeder extends Seeder
public function run()
{
User::truncate();
User::factory()->count(1)->firstAdmin()->create();
User::factory()->count(1)->snipeAdmin()->create();
User::factory()->count(3)->superuser()->create();
User::factory()->count(3)->admin()->create();
User::factory()->count(50)->viewAssets()->create();
if (! Company::count()) {
$this->call(CompanySeeder::class);
}
$companyIds = Company::all()->pluck('id');
User::factory()->count(1)->firstAdmin()->create(['company_id' => $companyIds->random()]);
User::factory()->count(1)->snipeAdmin()->create(['company_id' => $companyIds->random()]);
User::factory()->count(3)->superuser()->create(['company_id' => $companyIds->random()]);
User::factory()->count(3)->admin()->create(['company_id' => $companyIds->random()]);
User::factory()->count(50)->viewAssets()->create(['company_id' => $companyIds->random()]);
$src = public_path('/img/demo/avatars/');
$dst = 'avatars'.'/';