mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-12 16:44:08 -08:00
Seed license checkouts
This commit is contained in:
parent
92e0c59f89
commit
44a91f0a2b
|
@ -4,6 +4,8 @@ namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Actionlog;
|
use App\Models\Actionlog;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
use App\Models\License;
|
||||||
|
use App\Models\LicenseSeat;
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
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,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,5 +33,10 @@ class ActionlogSeeder extends Seeder
|
||||||
->count(100)
|
->count(100)
|
||||||
->assetCheckoutToLocation()
|
->assetCheckoutToLocation()
|
||||||
->create(['user_id' => $admin->id]);
|
->create(['user_id' => $admin->id]);
|
||||||
|
|
||||||
|
Actionlog::factory()
|
||||||
|
->count(20)
|
||||||
|
->licenseCheckoutToUser()
|
||||||
|
->create(['user_id' => $admin->id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue