feat: menambahkan kolom cashier_id ke tabel transactions
This commit is contained in:
parent
41f3d0d642
commit
195749fabc
@ -25,4 +25,9 @@ public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function cashier(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'cashier_id');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('transactions', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user