mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Seed assets with randomized locations
This commit is contained in:
parent
31630e3677
commit
daf6e9fa4b
|
@ -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 Illuminate\Database\Eloquent\Factories\Sequence;
|
||||||
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;
|
||||||
|
@ -28,97 +29,191 @@ class AssetSeeder extends Seeder
|
||||||
|
|
||||||
$supplierIds = Supplier::all()->pluck('id');
|
$supplierIds = Supplier::all()->pluck('id');
|
||||||
|
|
||||||
Asset::factory()->count(1000)->laptopMbp()->create([
|
Asset::factory()
|
||||||
'rtd_location_id' => $locationIds->random(),
|
->count(1000)
|
||||||
'supplier_id' => $supplierIds->random(),
|
->laptopMbp()
|
||||||
]);
|
->state(new Sequence(fn($sequence) => [
|
||||||
Asset::factory()->count(50)->laptopMbpPending()->create([
|
'rtd_location_id' => $locationIds->random(),
|
||||||
'rtd_location_id' => $locationIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
]))
|
||||||
]);
|
->create();
|
||||||
Asset::factory()->count(50)->laptopMbpArchived()->create([
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]);
|
|
||||||
Asset::factory()->count(50)->laptopAir()->create([
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]);
|
|
||||||
Asset::factory()->count(5)->laptopSurface()->create([
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]);
|
|
||||||
Asset::factory()->count(5)->laptopXps()->create([
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]);
|
|
||||||
Asset::factory()->count(5)->laptopSpectre()->create([
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]);
|
|
||||||
Asset::factory()->count(5)->laptopZenbook()->create([
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]);
|
|
||||||
Asset::factory()->count(3)->laptopYoga()->create([
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
Asset::factory()->count(30)->desktopMacpro()->create([
|
Asset::factory()
|
||||||
'rtd_location_id' => $locationIds->random(),
|
->count(50)
|
||||||
'supplier_id' => $supplierIds->random(),
|
->laptopMbpPending()
|
||||||
]);
|
->state(new Sequence(fn($sequence) => [
|
||||||
Asset::factory()->count(30)->desktopLenovoI5()->create([
|
'rtd_location_id' => $locationIds->random(),
|
||||||
'rtd_location_id' => $locationIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
]))
|
||||||
]);
|
->create();
|
||||||
Asset::factory()->count(30)->desktopOptiplex()->create([
|
|
||||||
'rtd_location_id' => $locationIds->random(),
|
|
||||||
'supplier_id' => $supplierIds->random(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
Asset::factory()->count(5)->confPolycom()->create([
|
Asset::factory()
|
||||||
'rtd_location_id' => $locationIds->random(),
|
->count(50)
|
||||||
'supplier_id' => $supplierIds->random(),
|
->laptopMbpArchived()
|
||||||
]);
|
->state(new Sequence(fn($sequence) => [
|
||||||
Asset::factory()->count(2)->confPolycomcx()->create([
|
'rtd_location_id' => $locationIds->random(),
|
||||||
'rtd_location_id' => $locationIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
]))
|
||||||
]);
|
->create();
|
||||||
|
|
||||||
Asset::factory()->count(12)->tabletIpad()->create([
|
Asset::factory()
|
||||||
'rtd_location_id' => $locationIds->random(),
|
->count(50)
|
||||||
'supplier_id' => $supplierIds->random(),
|
->laptopAir()
|
||||||
]);
|
->state(new Sequence(fn($sequence) => [
|
||||||
Asset::factory()->count(4)->tabletTab3()->create([
|
'rtd_location_id' => $locationIds->random(),
|
||||||
'rtd_location_id' => $locationIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
]))
|
||||||
]);
|
->create();
|
||||||
|
|
||||||
Asset::factory()->count(27)->phoneIphone11()->create([
|
Asset::factory()
|
||||||
'rtd_location_id' => $locationIds->random(),
|
->count(5)
|
||||||
'supplier_id' => $supplierIds->random(),
|
->laptopSurface()
|
||||||
]);
|
->state(new Sequence(fn($sequence) => [
|
||||||
Asset::factory()->count(40)->phoneIphone12()->create([
|
'rtd_location_id' => $locationIds->random(),
|
||||||
'rtd_location_id' => $locationIds->random(),
|
'supplier_id' => $supplierIds->random(),
|
||||||
'supplier_id' => $supplierIds->random(),
|
]))
|
||||||
]);
|
->create();
|
||||||
|
|
||||||
Asset::factory()->count(10)->ultrafine()->create([
|
Asset::factory()
|
||||||
'rtd_location_id' => $locationIds->random(),
|
->count(5)
|
||||||
'supplier_id' => $supplierIds->random(),
|
->laptopXps()
|
||||||
]);
|
->state(new Sequence(fn($sequence) => [
|
||||||
Asset::factory()->count(10)->ultrasharp()->create([
|
'rtd_location_id' => $locationIds->random(),
|
||||||
'rtd_location_id' => $locationIds->random(),
|
'supplier_id' => $supplierIds->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
|
||||||
Log::debug('Deleting: '.$del_files);
|
Log::debug('Deleting: ' . $del_files);
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete('assets'.'/'.$del_files);
|
Storage::disk('public')->delete('assets' . '/' . $del_files);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::debug($e);
|
Log::debug($e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue