URL Shortener 1.0
A Laravel-based URL shortener application
Chargement...
Recherche...
Aucune correspondance
DemoDataSeeder.php
Aller à la documentation de ce fichier.
1<?php
2
3namespace Database\Seeders;
4
7use Illuminate\Database\Seeder;
8use Illuminate\Support\Facades\Hash;
9
13class DemoDataSeeder extends Seeder
14{
18 public function run(): void
19 {
20 // Create a demo user
21 $demoUser = User::factory()->create([
22 'name' => 'Demo User',
23 'email' => 'demo@example.com',
24 'password' => Hash::make('0123456789'),
25 ]);
26
27 // Create demo URLs with specific codes
28 $demoUrls = [
29 [
30 'code' => '111111',
31 'original_url' => 'https://www.laravel.com/docs',
32 'description' => 'Laravel documentation',
33 'clicks' => 245,
34 'last_used_at' => now()->subDays(1),
35 ],
36 [
37 'code' => '222222',
38 'original_url' => 'https://github.com/laravel/laravel',
39 'description' => 'Laravel GitHub repository',
40 'clicks' => 89,
41 'last_used_at' => now()->subWeeks(2),
42 ],
43 [
44 'code' => '333333',
45 'original_url' => 'https://www.php.net',
46 'description' => 'Official PHP website',
47 'clicks' => 0,
48 'last_used_at' => null,
49 ],
50 [
51 'code' => '444444',
52 'original_url' => 'https://getbootstrap.com',
53 'description' => 'Bootstrap documentation',
54 'clicks' => 156,
55 'last_used_at' => now()->subDays(3),
56 ],
57 [
58 'code' => '555555',
59 'original_url' => 'https://developer.mozilla.org',
60 'description' => 'MDN Web Docs',
61 'clicks' => 412,
62 'last_used_at' => now()->subHours(6),
63 ]
64 ];
65
66 foreach ($demoUrls as $urlData) {
67 ShortUrl::factory()->create([
68 'user_id' => $demoUser->id,
69 'code' => $urlData['code'],
70 'original_url' => $urlData['original_url'],
71 'description' => $urlData['description'],
72 'clicks' => $urlData['clicks'],
73 'last_used_at' => $urlData['last_used_at'],
74 ]);
75 }
76
77 $this->command->info('Demo data created successfully!');
78 $this->command->info('Demo user: demo@example.com');
79 $this->command->info('Demo URLs with codes: 111111, 222222, 333333, 444444, 555555');
80 }
81}
Seeder for creating demo data.
run()
Run the database seeds.