Skip to content

Commit

Permalink
Add command to generate multiple photos
Browse files Browse the repository at this point in the history
  • Loading branch information
jolamemushaj committed Jan 10, 2024
1 parent 273c5ce commit 841e02e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
73 changes: 73 additions & 0 deletions app/Console/Commands/GenerateRandomPhotos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

use function Laravel\Prompts\progress;

class GenerateRandomPhotos extends Command
{
protected $signature = 'app:generate-random-photos';

public function handle(): void
{
$user = User::query()
->where('email', '[email protected]')
->first();

$bar = progress('Generating 1M photos with tags...', 1_000_000);

$bar->start();

$now = now()->toDateTimeString();

for ($i = 0; $i < 200; $i++) {
$photos = [];
$items = [];
$tags = [];

for ($j = 0; $j < 5000; $j++) {
$photos[] = [
'user_id' => $user->id,
'path' => 'photos/default.jpg',
'created_at' => $now,
'updated_at' => $now,
];
}

DB::table('photos')->insert($photos);

for ($j = 0; $j < 5000; $j++) {
$items[] = [
'photo_id' => $i * 5000 + $j + 2,
'item_id' => random_int(1, 300),
'picked_up' => 0,
'recycled' => 0,
'quantity' => 1,
'created_at' => $now,
'updated_at' => $now,
];
}

DB::table('photo_items')->insert($items);

for ($k = 0; $k < 5000; $k++) {
$tags[] = [
'photo_item_id' => $i * 5000 + $k + 1,
'tag_id' => random_int(1, 1500),
'created_at' => $now,
'updated_at' => $now,
];
}

DB::table('photo_item_tag')->insert($tags);

$bar->advance(5000);
}

$bar->finish();
}
}
9 changes: 9 additions & 0 deletions app/Filament/Resources/UserResource/Pages/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

use App\Filament\Resources\UserResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Hash;

class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
$data['password'] = Hash::make('password');
$data['email_verified_at'] = now();

return $data;
}
}
16 changes: 8 additions & 8 deletions database/seeders/UserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function run(): void
'password' => Hash::make('password'),
]);

$team = Team::factory()->create([
'name' => 'Team A',
'user_id' => $userA->id,
'personal_team' => true,
]);

$userA->teams()->attach($team);

tap(User::factory()->create([
'name' => 'Waste Wizard',
'email' => '[email protected]',
Expand All @@ -51,13 +59,5 @@ public function run(): void
'email' => '[email protected]',
'password' => Hash::make('password'),
]);

$team = Team::factory()->create([
'name' => 'Team A',
'user_id' => $userA->id,
'personal_team' => true,
]);

$userA->teams()->attach($team);
}
}

0 comments on commit 841e02e

Please sign in to comment.