From de5b7a0854da7f298b2760107bfa03b9dad6aecb Mon Sep 17 00:00:00 2001 From: arieeefajar Date: Thu, 13 Mar 2025 15:41:10 +0700 Subject: [PATCH] fix(master-land): add field user id --- app/Http/Controllers/MasterData/LandController.php | 2 ++ database/migrations/2025_01_28_065420_create_land_table.php | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/app/Http/Controllers/MasterData/LandController.php b/app/Http/Controllers/MasterData/LandController.php index ccb8e2d..1030e7f 100644 --- a/app/Http/Controllers/MasterData/LandController.php +++ b/app/Http/Controllers/MasterData/LandController.php @@ -85,6 +85,7 @@ public function store(Request $request) DB::beginTransaction(); try { $land = new Land(); + $land->user_id = Auth::user()->id; $land->owner = $request->owner; $land->province_code = $request->province_id; $land->regency_code = $request->regency_id; @@ -185,6 +186,7 @@ public function update(Request $request, $id) DB::beginTransaction(); try { $land = Land::findOrFail($id); + $land->user_id = Auth::user()->id; $land->owner = $request->owner; $land->province_code = $request->province_id; $land->regency_code = $request->regency_id; diff --git a/database/migrations/2025_01_28_065420_create_land_table.php b/database/migrations/2025_01_28_065420_create_land_table.php index b287d21..abfee23 100644 --- a/database/migrations/2025_01_28_065420_create_land_table.php +++ b/database/migrations/2025_01_28_065420_create_land_table.php @@ -13,6 +13,7 @@ public function up(): void { Schema::create('land', function (Blueprint $table) { $table->id(); + $table->unsignedBigInteger('user_id'); $table->string('owner'); $table->string('province_code'); $table->string('regency_code'); @@ -22,6 +23,10 @@ public function up(): void $table->string('longitude'); $table->timestamps(); }); + + Schema::table('land', function (Blueprint $table) { + $table->foreign('user_id')->references('id')->on('users'); + }); } /**