Make a few more factories a bit more pure
This commit is contained in:
parent
605f214597
commit
3849bb838d
6 changed files with 76 additions and 204 deletions
|
@ -40,9 +40,7 @@ class AccessoryFactory extends Factory
|
||||||
$this->faker->randomElement(['Bluetooth', 'Wired']),
|
$this->faker->randomElement(['Bluetooth', 'Wired']),
|
||||||
$this->faker->randomElement(['Keyboard', 'Wired'])
|
$this->faker->randomElement(['Keyboard', 'Wired'])
|
||||||
),
|
),
|
||||||
'user_id' => function () {
|
'user_id' => User::factory()->firstAdmin(),
|
||||||
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
|
|
||||||
},
|
|
||||||
'category_id' => Category::factory(),
|
'category_id' => Category::factory(),
|
||||||
'model_number' => $this->faker->numberBetween(1000000, 50000000),
|
'model_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||||
'location_id' => Location::factory(),
|
'location_id' => Location::factory(),
|
||||||
|
|
|
@ -36,9 +36,7 @@ class ActionlogFactory extends Factory
|
||||||
return [
|
return [
|
||||||
'item_id' => Asset::factory(),
|
'item_id' => Asset::factory(),
|
||||||
'item_type' => Asset::class,
|
'item_type' => Asset::class,
|
||||||
'user_id' => function () {
|
'user_id' => User::factory()->firstAdmin(),
|
||||||
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
|
|
||||||
},
|
|
||||||
'action_type' => 'uploaded',
|
'action_type' => 'uploaded',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,9 +46,7 @@ class AssetFactory extends Factory
|
||||||
'status_id' => function () {
|
'status_id' => function () {
|
||||||
return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']);
|
return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']);
|
||||||
},
|
},
|
||||||
'user_id' => function () {
|
'user_id' => User::factory()->firstAdmin(),
|
||||||
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
|
|
||||||
},
|
|
||||||
'asset_tag' => $this->faker->unixTime('now'),
|
'asset_tag' => $this->faker->unixTime('now'),
|
||||||
'notes' => 'Created by DB seeder',
|
'notes' => 'Created by DB seeder',
|
||||||
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
|
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Database\Seeders;
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use App\Models\Supplier;
|
use App\Models\Supplier;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
@ -29,23 +30,33 @@ class AccessorySeeder extends Seeder
|
||||||
|
|
||||||
$supplierIds = Supplier::all()->pluck('id');
|
$supplierIds = Supplier::all()->pluck('id');
|
||||||
|
|
||||||
Accessory::factory()->count(1)->appleUsbKeyboard()->create([
|
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||||
|
|
||||||
|
Accessory::factory()->appleUsbKeyboard()->create([
|
||||||
'location_id' => $locationIds->random(),
|
'location_id' => $locationIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
|
'user_id' => $admin->id,
|
||||||
]);
|
]);
|
||||||
Accessory::factory()->count(1)->appleBtKeyboard()->create([
|
|
||||||
|
Accessory::factory()->appleBtKeyboard()->create([
|
||||||
'location_id' => $locationIds->random(),
|
'location_id' => $locationIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
|
'user_id' => $admin->id,
|
||||||
]);
|
]);
|
||||||
Accessory::factory()->count(1)->appleMouse()->create([
|
|
||||||
|
Accessory::factory()->appleMouse()->create([
|
||||||
'location_id' => $locationIds->random(),
|
'location_id' => $locationIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
|
'user_id' => $admin->id,
|
||||||
]);
|
]);
|
||||||
Accessory::factory()->count(1)->microsoftMouse()->create([
|
|
||||||
|
Accessory::factory()->microsoftMouse()->create([
|
||||||
'location_id' => $locationIds->random(),
|
'location_id' => $locationIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
|
'user_id' => $admin->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$src = public_path('/img/demo/accessories/');
|
$src = public_path('/img/demo/accessories/');
|
||||||
$dst = 'accessories'.'/';
|
$dst = 'accessories'.'/';
|
||||||
$del_files = Storage::files($dst);
|
$del_files = Storage::files($dst);
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Database\Seeders;
|
||||||
use App\Models\Actionlog;
|
use App\Models\Actionlog;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class ActionlogSeeder extends Seeder
|
class ActionlogSeeder extends Seeder
|
||||||
|
@ -21,14 +22,16 @@ class ActionlogSeeder extends Seeder
|
||||||
$this->call(LocationSeeder::class);
|
$this->call(LocationSeeder::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||||
|
|
||||||
Actionlog::factory()
|
Actionlog::factory()
|
||||||
->count(300)
|
->count(300)
|
||||||
->assetCheckoutToUser()
|
->assetCheckoutToUser()
|
||||||
->create();
|
->create(['user_id' => $admin->id]);
|
||||||
|
|
||||||
Actionlog::factory()
|
Actionlog::factory()
|
||||||
->count(100)
|
->count(100)
|
||||||
->assetCheckoutToLocation()
|
->assetCheckoutToLocation()
|
||||||
->create();
|
->create(['user_id' => $admin->id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Database\Seeders;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use App\Models\Supplier;
|
use App\Models\Supplier;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Sequence;
|
use Illuminate\Database\Eloquent\Factories\Sequence;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
@ -13,201 +14,41 @@ use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class AssetSeeder extends Seeder
|
class AssetSeeder extends Seeder
|
||||||
{
|
{
|
||||||
|
private $admin;
|
||||||
|
private $locationIds;
|
||||||
|
private $supplierIds;
|
||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
Asset::truncate();
|
Asset::truncate();
|
||||||
|
|
||||||
if (! Location::count()) {
|
$this->ensureLocationsSeeded();
|
||||||
$this->call(LocationSeeder::class);
|
$this->ensureSuppliersSeeded();
|
||||||
}
|
|
||||||
|
|
||||||
$locationIds = Location::all()->pluck('id');
|
$this->admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||||
|
$this->locationIds = Location::all()->pluck('id');
|
||||||
|
$this->supplierIds = Supplier::all()->pluck('id');
|
||||||
|
|
||||||
if (! Supplier::count()) {
|
Asset::factory()->count(1000)->laptopMbp()->state(new Sequence($this->getState()))->create();
|
||||||
$this->call(SupplierSeeder::class);
|
Asset::factory()->count(50)->laptopMbpPending()->state(new Sequence($this->getState()))->create();
|
||||||
}
|
Asset::factory()->count(50)->laptopMbpArchived()->state(new Sequence($this->getState()))->create();
|
||||||
|
Asset::factory()->count(50)->laptopAir()->state(new Sequence($this->getState()))->create();
|
||||||
$supplierIds = Supplier::all()->pluck('id');
|
Asset::factory()->count(5)->laptopSurface()->state(new Sequence($this->getState()))->create();
|
||||||
|
Asset::factory()->count(5)->laptopXps()->state(new Sequence($this->getState()))->create();
|
||||||
Asset::factory()
|
Asset::factory()->count(5)->laptopSpectre()->state(new Sequence($this->getState()))->create();
|
||||||
->count(1000)
|
Asset::factory()->count(5)->laptopZenbook()->state(new Sequence($this->getState()))->create();
|
||||||
->laptopMbp()
|
Asset::factory()->count(3)->laptopYoga()->state(new Sequence($this->getState()))->create();
|
||||||
->state(new Sequence(fn($sequence) => [
|
Asset::factory()->count(30)->desktopMacpro()->state(new Sequence($this->getState()))->create();
|
||||||
'rtd_location_id' => $locationIds->random(),
|
Asset::factory()->count(30)->desktopLenovoI5()->state(new Sequence($this->getState()))->create();
|
||||||
'supplier_id' => $supplierIds->random(),
|
Asset::factory()->count(30)->desktopOptiplex()->state(new Sequence($this->getState()))->create();
|
||||||
]))
|
Asset::factory()->count(5)->confPolycom()->state(new Sequence($this->getState()))->create();
|
||||||
->create();
|
Asset::factory()->count(2)->confPolycomcx()->state(new Sequence($this->getState()))->create();
|
||||||
|
Asset::factory()->count(12)->tabletIpad()->state(new Sequence($this->getState()))->create();
|
||||||
Asset::factory()
|
Asset::factory()->count(4)->tabletTab3()->state(new Sequence($this->getState()))->create();
|
||||||
->count(50)
|
Asset::factory()->count(27)->phoneIphone11()->state(new Sequence($this->getState()))->create();
|
||||||
->laptopMbpPending()
|
Asset::factory()->count(40)->phoneIphone12()->state(new Sequence($this->getState()))->create();
|
||||||
->state(new Sequence(fn($sequence) => [
|
Asset::factory()->count(10)->ultrafine()->state(new Sequence($this->getState()))->create();
|
||||||
'rtd_location_id' => $locationIds->random(),
|
Asset::factory()->count(10)->ultrasharp()->state(new Sequence($this->getState()))->create();
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(50)
|
|
||||||
->laptopMbpArchived()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(50)
|
|
||||||
->laptopAir()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(5)
|
|
||||||
->laptopSurface()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(5)
|
|
||||||
->laptopXps()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(5)
|
|
||||||
->laptopSpectre()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(5)
|
|
||||||
->laptopZenbook()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(3)
|
|
||||||
->laptopYoga()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(30)
|
|
||||||
->desktopMacpro()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(30)
|
|
||||||
->desktopLenovoI5()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(30)
|
|
||||||
->desktopOptiplex()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(5)
|
|
||||||
->confPolycom()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(2)
|
|
||||||
->confPolycomcx()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(12)
|
|
||||||
->tabletIpad()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(4)
|
|
||||||
->tabletTab3()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(27)
|
|
||||||
->phoneIphone11()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(40)
|
|
||||||
->phoneIphone12()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(10)
|
|
||||||
->ultrafine()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
Asset::factory()
|
|
||||||
->count(10)
|
|
||||||
->ultrasharp()
|
|
||||||
->state(new Sequence(fn($sequence) => [
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]))
|
|
||||||
->create();
|
|
||||||
|
|
||||||
$del_files = Storage::files('assets');
|
$del_files = Storage::files('assets');
|
||||||
foreach ($del_files as $del_file) { // iterate files
|
foreach ($del_files as $del_file) { // iterate files
|
||||||
|
@ -221,4 +62,27 @@ class AssetSeeder extends Seeder
|
||||||
|
|
||||||
DB::table('checkout_requests')->truncate();
|
DB::table('checkout_requests')->truncate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function ensureLocationsSeeded()
|
||||||
|
{
|
||||||
|
if (! Location::count()) {
|
||||||
|
$this->call(LocationSeeder::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function ensureSuppliersSeeded()
|
||||||
|
{
|
||||||
|
if (! Supplier::count()) {
|
||||||
|
$this->call(SupplierSeeder::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getState()
|
||||||
|
{
|
||||||
|
return fn($sequence) => [
|
||||||
|
'rtd_location_id' => $this->locationIds->random(),
|
||||||
|
'supplier_id' => $this->supplierIds->random(),
|
||||||
|
'user_id' => $this->admin->id,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue