Selaa lähdekoodia

fix email

master
Amirul Anwar 1 viikko sitten
vanhempi
commit
74de9657bb
4 muutettua tiedostoa jossa 86 lisäystä ja 29 poistoa
  1. 59
    0
      app/Console/Commands/ScrapBookingUserId.php
  2. 13
    0
      app/Models/Agent.php
  3. 13
    0
      app/Models/Booking.php
  4. 1
    29
      app/Models/User.php

+ 59
- 0
app/Console/Commands/ScrapBookingUserId.php Näytä tiedosto

@@ -0,0 +1,59 @@
1
+<?php
2
+
3
+namespace App\Console\Commands;
4
+
5
+use App\Models\Agent;
6
+use App\Models\Booking;
7
+use App\Models\User;
8
+use Illuminate\Console\Command;
9
+
10
+class ScrapBookingUserId extends Command
11
+{
12
+    /**
13
+     * The name and signature of the console command.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $signature = 'booking:scrap';
18
+
19
+    /**
20
+     * The console command description.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $description = 'Command description';
25
+
26
+    /**
27
+     * Execute the console command.
28
+     *
29
+     * @return int
30
+     */
31
+    public function handle()
32
+    {
33
+
34
+        while(true){
35
+            $bookings = Booking::where('user_id',null)->get();
36
+            foreach ($bookings as $booking) {
37
+                // Find the user that matches the email in the booking
38
+                $user = User::where('email', $booking->contact_email)->first();
39
+                
40
+                if ($user) {
41
+                    // Update the user_id in the booking record
42
+                    $booking->user_id = $user->id;
43
+                    
44
+                    // // Check if the user is an agent
45
+                    // $agent = Agent::where('user_id', $user->id)->first();
46
+                    // if ($agent) {
47
+                    //     $booking->agent_id = $agent->id;
48
+                    //     $booking->agent_code = $agent->code;
49
+                    // }
50
+        
51
+                    // Save the updated booking
52
+                    $booking->save();
53
+                }
54
+            }
55
+            
56
+            return $this->info('Booking user IDs updated based on user emails.');
57
+        }
58
+    }
59
+}

+ 13
- 0
app/Models/Agent.php Näytä tiedosto

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Agent extends Model
9
+{
10
+    use HasFactory;
11
+    protected $table = 'agents';
12
+
13
+}

+ 13
- 0
app/Models/Booking.php Näytä tiedosto

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Booking extends Model
9
+{
10
+    use HasFactory;
11
+    protected $table = 'bookings';
12
+
13
+}

+ 1
- 29
app/Models/User.php Näytä tiedosto

@@ -12,33 +12,5 @@ class User extends Authenticatable
12 12
 {
13 13
     use HasApiTokens, HasFactory, Notifiable;
14 14
 
15
-    /**
16
-     * The attributes that are mass assignable.
17
-     *
18
-     * @var array<int, string>
19
-     */
20
-    protected $fillable = [
21
-        'name',
22
-        'email',
23
-        'password',
24
-    ];
25
-
26
-    /**
27
-     * The attributes that should be hidden for serialization.
28
-     *
29
-     * @var array<int, string>
30
-     */
31
-    protected $hidden = [
32
-        'password',
33
-        'remember_token',
34
-    ];
35
-
36
-    /**
37
-     * The attributes that should be cast.
38
-     *
39
-     * @var array<string, string>
40
-     */
41
-    protected $casts = [
42
-        'email_verified_at' => 'datetime',
43
-    ];
15
+    protected $table = 'users';
44 16
 }

Loading…
Peruuta
Tallenna