mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-13 06:47:46 -08:00
Remove hard-coded company_id in factories and update seeders
This commit is contained in:
parent
fb789eb048
commit
b944945377
|
@ -59,7 +59,6 @@ class ComponentFactory extends Factory
|
||||||
'qty' => 10,
|
'qty' => 10,
|
||||||
'min_amt' => 2,
|
'min_amt' => 2,
|
||||||
'location_id' => 3,
|
'location_id' => 3,
|
||||||
'company_id' => 2,
|
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\Manufacturer;
|
use App\Models\Manufacturer;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
@ -42,6 +43,7 @@ class ConsumableFactory extends Factory
|
||||||
'purchase_cost' => $this->faker->randomFloat(2, 1, 50),
|
'purchase_cost' => $this->faker->randomFloat(2, 1, 50),
|
||||||
'qty' => $this->faker->numberBetween(5, 10),
|
'qty' => $this->faker->numberBetween(5, 10),
|
||||||
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
|
'min_amt' => $this->faker->numberBetween($min = 1, $max = 2),
|
||||||
|
'company_id' => Company::factory(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +60,6 @@ class ConsumableFactory extends Factory
|
||||||
},
|
},
|
||||||
'qty' => 10,
|
'qty' => 10,
|
||||||
'min_amt' => 2,
|
'min_amt' => 2,
|
||||||
'company_id' => 3,
|
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use \Auth;
|
use \Auth;
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ class UserFactory extends Factory
|
||||||
'activated' => 1,
|
'activated' => 1,
|
||||||
'address' => $this->faker->address(),
|
'address' => $this->faker->address(),
|
||||||
'city' => $this->faker->city(),
|
'city' => $this->faker->city(),
|
||||||
'company_id' => rand(1, 4),
|
'company_id' => Company::factory(),
|
||||||
'country' => $this->faker->country(),
|
'country' => $this->faker->country(),
|
||||||
'department_id' => rand(1, 6),
|
'department_id' => rand(1, 6),
|
||||||
'email' => $this->faker->safeEmail,
|
'email' => $this->faker->safeEmail,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\Component;
|
use App\Models\Component;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
@ -12,9 +13,16 @@ class ComponentSeeder extends Seeder
|
||||||
{
|
{
|
||||||
Component::truncate();
|
Component::truncate();
|
||||||
DB::table('components_assets')->truncate();
|
DB::table('components_assets')->truncate();
|
||||||
Component::factory()->count(1)->ramCrucial4()->create(); // 1
|
|
||||||
Component::factory()->count(1)->ramCrucial8()->create(); // 1
|
if (! Company::count()) {
|
||||||
Component::factory()->count(1)->ssdCrucial120()->create(); // 1
|
$this->call(CompanySeeder::class);
|
||||||
Component::factory()->count(1)->ssdCrucial240()->create(); // 1
|
}
|
||||||
|
|
||||||
|
$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()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
@ -17,11 +18,18 @@ class UserSeeder extends Seeder
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
User::truncate();
|
User::truncate();
|
||||||
User::factory()->count(1)->firstAdmin()->create();
|
|
||||||
User::factory()->count(1)->snipeAdmin()->create();
|
if (! Company::count()) {
|
||||||
User::factory()->count(3)->superuser()->create();
|
$this->call(CompanySeeder::class);
|
||||||
User::factory()->count(3)->admin()->create();
|
}
|
||||||
User::factory()->count(50)->viewAssets()->create();
|
|
||||||
|
$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/');
|
$src = public_path('/img/demo/avatars/');
|
||||||
$dst = 'avatars'.'/';
|
$dst = 'avatars'.'/';
|
||||||
|
|
Loading…
Reference in a new issue