Seed license checkouts

This commit is contained in:
Marcus Moore 2023-03-20 14:18:54 -07:00
parent 92e0c59f89
commit 44a91f0a2b
No known key found for this signature in database
2 changed files with 29 additions and 0 deletions

View file

@ -4,6 +4,8 @@ namespace Database\Factories;
use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\Location;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
@ -81,4 +83,26 @@ class ActionlogFactory extends Factory
];
});
}
public function licenseCheckoutToUser()
{
return $this->state(function () {
$target = User::inRandomOrder()->first();
$licenseSeat = LicenseSeat::whereNull('assigned_to')->inRandomOrder()->first();
$licenseSeat->update([
'assigned_to' => $target->id,
'user_id' => 1, // not ideal but works
]);
return [
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
'action_type' => 'checkout',
'item_id' => $licenseSeat->license->id,
'item_type' => License::class,
'target_id' => $target->id,
'target_type' => User::class,
];
});
}
}

View file

@ -33,5 +33,10 @@ class ActionlogSeeder extends Seeder
->count(100)
->assetCheckoutToLocation()
->create(['user_id' => $admin->id]);
Actionlog::factory()
->count(20)
->licenseCheckoutToUser()
->create(['user_id' => $admin->id]);
}
}