diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 54fb1e088b..3507a106ef 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -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); diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 7b6ad44687..2eba6f3721 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -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'.'/';