diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniController.php b/app/Http/Controllers/Web/Produktivitas/PetaniController.php new file mode 100644 index 0000000..2808ba7 --- /dev/null +++ b/app/Http/Controllers/Web/Produktivitas/PetaniController.php @@ -0,0 +1,163 @@ +get(); + + $query = Petani::with('desakelurahan') + ->orderBy('created_at', 'desc'); + + if ($request->search) { + $query->where(function ($query) use ($request) { + $query->where('nama', 'like', '%' . $request->search . '%') + ->orWhere('ktp', 'like', '%' . $request->search . '%'); + }); + } + + $petani = $query->paginate($request->per_page ?? 10); + + return view('produktivitas.petani.index', compact('petani', 'provinsi')); + } + + public function create() + { + if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { + abort(403); + } + + $pendidikan = Pendidikan::options(); + $pekerjaan = Pekerjaan::options(); + $pernikahan = Pernikahan::options(); + + $provinsi = Provinsi::orderBy('kode', 'asc')->get(); + + return view('produktivitas.petani.add', compact('pendidikan', 'pekerjaan', + 'pernikahan', 'provinsi')); + } + + public function store(Request $request) + { + if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { + abort(403); + } + + $validatedData = $request->validate([ + 'nama' => ['required','string','max:255'], + 'jenis_kelamin' => ['required','boolean'], + 'tempat_lahir' => ['required','string','max:255'], + 'tanggal_lahir' => ['required','date'], + 'pendidikan_terakhir' => ['required', Rule::enum(Pendidikan::class)], + 'alamat' => ['required','string','max:500'], + 'desa_kelurahan_id' => ['required','exists:master_desa_kelurahan,id'], + //'komoditas_id' => ['required','exists:master_komoditas,id'], + 'status_perkawinan' => ['required', Rule::enum(Pernikahan::class)], + 'ktp' => ['nullable', 'min:16', 'max:16'], + 'file_ktp' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'], + 'kk' => ['nullable', 'min:16', 'max:16'], + 'file_kk' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'], + 'foto' => ['nullable', 'file', 'mimes:jpeg,jpg,png', 'max:2048'], + ]); + + Petani::create([...$validatedData, + 'uid' => 'PTN-'. strtoupper(Str::random(10)), + 'created_by' => auth()->id(), + 'updated_by' => auth()->id()]); + + return redirect()->route('petani.index')->with('success', 'Data petani berhasil ditambahkan.'); + } + + public function show(string $id) + { + if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { + abort(403); + } + + $petani = Petani::findOrFail($id); + + return view('produktivitas.petani.view', compact('petani')); + } + + + public function edit(string $id, Request $request) + { + if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { + abort(403); + } + + $petani = Petani::findOrFail($id); + + $pendidikan = Pendidikan::options(); + $pekerjaan = Pekerjaan::options(); + $pernikahan = Pernikahan::options(); + + $provinsi = Provinsi::all(); + + $section = $request->section ?? 'budidaya'; + + return view('produktivitas.petani.edit', compact('petani', 'pendidikan', 'pekerjaan', + 'pernikahan', 'provinsi', 'section')); + } + + + public function update(Request $request, string $id) + { + if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { + abort(403); + } + + $petani = Petani::findOrFail($id); + + $validatedData = $request->validate([ + 'nama' => ['required','string','max:255'], + 'jenis_kelamin' => ['required','boolean'], + 'tempat_lahir' => ['required','string','max:255'], + 'tanggal_lahir' => ['required','date'], + 'pendidikan_terakhir' => ['required', Rule::enum(Pendidikan::class)], + 'alamat' => ['required','string','max:500'], + 'desa_kelurahan_id' => ['required','exists:master_desa_kelurahan,id'], + //'komoditas_id' => ['required','exists:master_komoditas,id'], + 'status_perkawinan' => ['required', Rule::enum(Pernikahan::class)], + 'ktp' => ['nullable', 'min:16', 'max:16'], + 'file_ktp' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'], + 'kk' => ['nullable', 'min:16', 'max:16'], + 'file_kk' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'], + 'foto' => ['nullable', 'file', 'mimes:jpeg,jpg,png', 'max:2048'], + ]); + + $petani->update([...$validatedData, + 'updated_by' => auth()->id()]); + + return redirect()->route('petani.index')->with('success', 'Data petani berhasil diupdate.'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } +} diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php new file mode 100644 index 0000000..bb97bc0 --- /dev/null +++ b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php @@ -0,0 +1,90 @@ +orderBy('created_at', 'desc') + ->paginate($request->per_page ?? 10); + + return view('produktivitas.petani.lahan.index', compact('petani', 'lahan')); + } + + public function create($petaniId) + { + if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { + abort(403); + } + + $petani = Petani::findOrFail($petaniId); + + $lahan = Lahan::where('petani_id', $petaniId) + ->orderBy('created_at', 'desc') + ->paginate($request->per_page ?? 10); + + $provinsi = Provinsi::orderBy('kode', 'asc')->get(); + + $komoditas = Komoditas::all(); + + return view('produktivitas.petani.lahan.add', compact('petani', 'lahan', 'provinsi', 'komoditas')); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + */ + public function show(string $id) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } +} diff --git a/app/Models/Map/Lahan.php b/app/Models/Map/Lahan.php index 671c45c..eeac4fb 100644 --- a/app/Models/Map/Lahan.php +++ b/app/Models/Map/Lahan.php @@ -16,6 +16,7 @@ class Lahan extends Model 'nama', 'status_kepemilikan', 'profile_id', + 'petani_id', 'desa_kelurahan_id', 'uid', 'path', diff --git a/database/migrations/2026_06_26_180741_create_petani_master_table.php b/database/migrations/2026_06_26_180741_create_petani_master_table.php index 6e3efed..dc2d06d 100644 --- a/database/migrations/2026_06_26_180741_create_petani_master_table.php +++ b/database/migrations/2026_06_26_180741_create_petani_master_table.php @@ -52,6 +52,6 @@ return new class extends Migration */ public function down(): void { - Schema::dropIfExists('petanis'); + Schema::dropIfExists('petani'); } }; diff --git a/database/migrations/2026_06_28_095941_update_lahan_table.php b/database/migrations/2026_06_28_095941_update_lahan_table.php new file mode 100644 index 0000000..a54c02e --- /dev/null +++ b/database/migrations/2026_06_28_095941_update_lahan_table.php @@ -0,0 +1,47 @@ +foreignId('petani_id')->nullable()->constrained('petani')->onDelete('set null'); + + $table->foreignId('komoditas_id')->nullable()->constrained('master_komoditas')->onDelete('set null'); + $table->foreignId('jenis_komoditas_id')->nullable()->constrained('jenis_komoditas')->onDelete('set null'); + $table->foreignId('varietas_id')->nullable()->constrained('master_varietas')->onDelete('set null'); + + $table->float('umur_tanaman', 8)->nullable(); + $table->float('umur_kebun', 8)->nullable(); + + $table->integer('jumlah_tanaman')->nullable(); + + $table->string('kondisi_tanaman')->nullable(); + $table->string('hama_tanaman')->nullable(); + $table->string('penyakit_tanaman')->nullable(); + $table->string('keparahan_serangan')->nullable(); + + // TODO: + // komoditas lainnya dan tanaman penaung + }); + + Schema::table('petani', function (Blueprint $table) { + $table->foreignId('profile_id')->nullable()->constrained('profiles')->onDelete('set null'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + + } +}; diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 4eda5f9..f65225a 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -4,7 +4,7 @@