diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php index 4386583..e573be1 100644 --- a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php +++ b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php @@ -140,9 +140,21 @@ class PetaniLahanController extends Controller $komoditas = Komoditas::where('id', $request->komoditas_id)->first(); $lahanCount = Lahan::where('petani_id', $petaniId) ->count(); - $lahanUid = strtoupper(Str::random(10)); + + if ($request->hasFile('foto')) { + $foto = []; + foreach ($request->file('foto') as $file) { + $path = $file->store('lahan', 'public'); + $foto[] = [ + 'path' => $path, + 'file' => $file->getClientOriginalName(), + ]; + } + } + $lahan = Lahan::create([...$validated, + 'foto' => $foto && count($foto) > 0 ? json_encode($foto) : null, 'nama' => 'Lahan ' . $komoditas->nama . ' #' . ($lahanCount + 1), 'uid' => 'LHN-' . $petani->uid . '-' . $lahanUid, 'petani_id' => $petaniId, diff --git a/database/migrations/2026_07_07_135321_update_petani_master_dan_lahan_table.php b/database/migrations/2026_07_07_135321_update_petani_master_dan_lahan_table.php index faf26fa..74393e1 100644 --- a/database/migrations/2026_07_07_135321_update_petani_master_dan_lahan_table.php +++ b/database/migrations/2026_07_07_135321_update_petani_master_dan_lahan_table.php @@ -11,9 +11,16 @@ return new class extends Migration */ public function up(): void { + Schema::table('petani', function (Blueprint $table) { + $table->foreignId('komoditas_id')->nullable()->constrained('master_komoditas')->onDelete('set null'); + + }); + Schema::table('map_lahan', function (Blueprint $table) { $table->json('komoditas_lain')->nullable(); $table->json('tanaman_penaung')->nullable(); + + $table->json('foto')->nullable(); }); } diff --git a/resources/views/produktivitas/petani/lahan/add.blade.php b/resources/views/produktivitas/petani/lahan/add.blade.php index 73c2bbb..a49106f 100644 --- a/resources/views/produktivitas/petani/lahan/add.blade.php +++ b/resources/views/produktivitas/petani/lahan/add.blade.php @@ -3,6 +3,7 @@ @push('style') +