foto lahan

This commit is contained in:
2026-07-13 01:04:55 +07:00
parent c5b5721b31
commit 599269410b
4 changed files with 108 additions and 11 deletions
@@ -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,