diff --git a/app/Enums/KondisiTanaman.php b/app/Enums/KondisiTanaman.php index d8d8bdd..a1a8c64 100644 --- a/app/Enums/KondisiTanaman.php +++ b/app/Enums/KondisiTanaman.php @@ -6,6 +6,6 @@ enum KondisiTanaman: string { case BAIK = 'baik'; case SEDANG = 'sedang'; - case SAKIT = 'sakit'; + case BURUK = 'buruk'; case MATI = 'mati'; } diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniController.php b/app/Http/Controllers/Web/Produktivitas/PetaniController.php index 2808ba7..4723bfc 100644 --- a/app/Http/Controllers/Web/Produktivitas/PetaniController.php +++ b/app/Http/Controllers/Web/Produktivitas/PetaniController.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; +use Illuminate\Support\Facades\Storage; use App\Models\Wilayah\Provinsi; use App\Models\Pertanian\Petani; @@ -75,12 +76,28 @@ class PetaniController extends Controller //'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'], + 'file_ktp' => ['nullable', 'image', 'mimes:jpeg,jpg,png', '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'], + 'file_kk' => ['nullable', 'image', 'mimes:jpeg,jpg,png', 'max:2048'], + 'foto' => ['nullable', 'image', 'mimes:jpeg,jpg,png', 'max:2048'], + 'nomor_telepon' => ['nullable', 'numeric', 'max:20'], ]); + if ($request->hasFile('file_ktp')) { + $file_ktp = $request->file('file_ktp'); + $validatedData['path_ktp'] = $file_ktp->store('petani/ktp'); + $validatedData['file_ktp'] = $file_ktp->getClientOriginalName(); + } + if ($request->hasFile('file_kk')) { + $file_kk = $request->file('file_kk'); + $validatedData['path_kk'] = $file_kk->store('petani/kk'); + $validatedData['file_kk'] = $file_kk->getClientOriginalName(); + } + if ($request->hasFile('foto')) { + $file_foto = $request->file('foto'); + $validatedData['foto'] = $file_foto->store('petani/foto'); + } + Petani::create([...$validatedData, 'uid' => 'PTN-'. strtoupper(Str::random(10)), 'created_by' => auth()->id(), @@ -145,8 +162,24 @@ class PetaniController extends Controller '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'], + 'nomor_telepon' => ['nullable', 'numeric', 'max:20'], ]); + if ($request->hasFile('file_ktp')) { + $file_ktp = $request->file('file_ktp'); + $validatedData['path_ktp'] = $file_ktp->store('petani/ktp'); + $validatedData['file_ktp'] = $file_ktp->getClientOriginalName(); + } + if ($request->hasFile('file_kk')) { + $file_kk = $request->file('file_kk'); + $validatedData['path_kk'] = $file_kk->store('petani/kk'); + $validatedData['file_kk'] = $file_kk->getClientOriginalName(); + } + if ($request->hasFile('foto')) { + $file_foto = $request->file('foto'); + $validatedData['foto'] = $file_foto->store('petani/foto'); + } + $petani->update([...$validatedData, 'updated_by' => auth()->id()]); @@ -160,4 +193,33 @@ class PetaniController extends Controller { // } + + public function showImage(string $id, string $field) + { + if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { + abort(403); + } + + $petani = Petani::findOrFail($id); + + switch ($field) { + case 'ktp': + $filePath = $petani->path_ktp; + break; + case 'kk': + $filePath = $petani->path_kk; + break; + case 'foto': + $filePath = $petani->foto; + break; + default: + abort(404); + } + + if (!$filePath || !\Storage::exists($filePath)) { + abort(404); + } + + return Storage::disk('local')->response($filePath); + } } diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php index 13163e0..b4f0104 100644 --- a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php +++ b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php @@ -56,7 +56,7 @@ class PetaniLahanController extends Controller $petani = Petani::findOrFail($petaniId); $lahan = Lahan::where('petani_id', $petaniId) - ->orderBy('created_at', 'desc') + ->orderBy('id', 'asc') ->get(); $provinsi = Provinsi::orderBy('kode', 'asc')->get(); @@ -171,9 +171,6 @@ class PetaniLahanController extends Controller return view('produktivitas.petani.lahan.edit', compact('lahan', 'lahanSelected', 'petani', 'komoditas', 'provinsi')); } - /** - * Update the specified resource in storage. - */ public function update(Request $request, string $petaniId, string $id) { if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { diff --git a/resources/views/produktivitas/petani/add.blade.php b/resources/views/produktivitas/petani/add.blade.php index f070736..c42e23a 100644 --- a/resources/views/produktivitas/petani/add.blade.php +++ b/resources/views/produktivitas/petani/add.blade.php @@ -2,122 +2,196 @@ @section('content')
Alamat: {{ $petani ? $petani->alamat : 'Alamat' }}
+{{ $petani ? $petani->desaKelurahan->nama : 'Desa/Kelurahan' }}, {{ $petani ? $petani->desaKelurahan->kecamatan->nama : 'Kecamatan' }}, {{ $petani ? $petani->desaKelurahan->kecamatan->kabupatenKota->nama : 'Kabupaten/Kota' }}, {{ $petani ? $petani->desaKelurahan->kecamatan->kabupatenKota->provinsi->nama : 'Provinsi' }}
+