Seed users with departments

This commit is contained in:
Marcus Moore 2023-03-16 13:25:35 -07:00
parent 345946d6d4
commit a98cc01766
No known key found for this signature in database
2 changed files with 43 additions and 6 deletions

View file

@ -38,9 +38,9 @@ class DatabaseSeeder extends Seeder
$this->call(CompanySeeder::class);
$this->call(CategorySeeder::class);
$this->call(LocationSeeder::class);
$this->call(DepartmentSeeder::class);
$this->call(UserSeeder::class);
$this->call(DepreciationSeeder::class);
$this->call(DepartmentSeeder::class);
$this->call(ManufacturerSeeder::class);
$this->call(SupplierSeeder::class);
$this->call(AssetModelSeeder::class);

View file

@ -3,7 +3,9 @@
namespace Database\Seeders;
use App\Models\Company;
use App\Models\Department;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Sequence;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Log;
@ -25,11 +27,46 @@ class UserSeeder extends Seeder
$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()]);
if (! Department::count()) {
$this->call(DepartmentSeeder::class);
}
$departmentIds = Department::all()->pluck('id');
User::factory()->count(1)->firstAdmin()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
User::factory()->count(1)->snipeAdmin()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
User::factory()->count(3)->superuser()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
User::factory()->count(3)->admin()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
User::factory()->count(50)->viewAssets()
->state(new Sequence(fn($sequence) => [
'company_id' => $companyIds->random(),
'department_id' => $departmentIds->random(),
]))
->create();
$src = public_path('/img/demo/avatars/');
$dst = 'avatars'.'/';