diff --git a/app/Models/Biography.php b/app/Models/Biography.php index 48a3ad3..83eb9c8 100644 --- a/app/Models/Biography.php +++ b/app/Models/Biography.php @@ -25,4 +25,9 @@ public function user(): BelongsTo { return $this->belongsTo(User::class); } + + public function cashier(): BelongsTo + { + return $this->belongsTo(User::class, 'cashier_id'); + } } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index ffac151..a58668e 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -17,6 +17,7 @@ class Transaction extends Model protected $fillable = [ 'user_id', + 'cashier_id', 'barbershop_id', 'customer_id', 'service_id', @@ -47,6 +48,11 @@ public function user(): BelongsTo return $this->belongsTo(User::class); } + public function cashier(): BelongsTo + { + return $this->belongsTo(User::class, 'cashier_id'); + } + public function barbershop(): BelongsTo { return $this->belongsTo(Barbershop::class); diff --git a/database/migrations/2024_12_23_203227_add_cashier_id_to_transactions.php b/database/migrations/2024_12_23_203227_add_cashier_id_to_transactions.php new file mode 100644 index 0000000..47f3dfa --- /dev/null +++ b/database/migrations/2024_12_23_203227_add_cashier_id_to_transactions.php @@ -0,0 +1,39 @@ +foreignId('cashier_id') + ->after('user_id') + ->nullable() + ->constrained('users') + ->cascadeOnDelete(); + }); + + $getFirstCashier = User::where('role_id', 4)->first(); + DB::table('transactions')->update(['cashier_id' => $getFirstCashier->id]); + + Schema::table('transactions', function (Blueprint $table) { + $table->foreignId('cashier_id')->nullable(false)->change(); + }); + } + + public function down(): void + { + Schema::table('transactions', function (Blueprint $table) { + $table->dropForeign(['cashier_id']); + $table->dropColumn('cashier_id'); + }); + } +};