From 81a0553379428f20a24804aa8607c0c947f74fa1 Mon Sep 17 00:00:00 2001 From: rahmagustin Date: Fri, 13 Mar 2026 05:14:06 +0700 Subject: [PATCH] add tps --- app/Http/Controllers/Admin/TpsController.php | 63 +--- .../views/admin/kategori-tps/edit.blade.php | 88 ++++-- .../views/admin/kategori-tps/index.blade.php | 296 ++++++++++------- resources/views/admin/tps/edit.blade.php | 299 +++++++++--------- resources/views/admin/tps/index.blade.php | 10 +- 5 files changed, 404 insertions(+), 352 deletions(-) diff --git a/app/Http/Controllers/Admin/TpsController.php b/app/Http/Controllers/Admin/TpsController.php index 5e12718..5cd370c 100644 --- a/app/Http/Controllers/Admin/TpsController.php +++ b/app/Http/Controllers/Admin/TpsController.php @@ -7,6 +7,7 @@ use App\Models\LokasiTps; use App\Models\KategoriTps; use Illuminate\Support\Facades\Validator; +use Illuminate\Support\Facades\Storage; class TpsController extends Controller { @@ -22,7 +23,7 @@ public function index(Request $request) ->when($search, function ($query) use ($search) { $query->where('nama_tps', 'like', '%' . $search . '%'); }) - ->orderBy('id_tps', 'desc') // supaya data terbaru muncul di atas + ->orderBy('id_tps', 'desc') ->paginate(10); return view('admin.tps.index', compact('title', 'tps', 'search')); @@ -33,6 +34,7 @@ public function create() { $title = 'Tambah TPS'; $kategori = KategoriTps::all(); + return view('admin.tps.create', compact('title', 'kategori')); } @@ -55,9 +57,12 @@ private function convertToDecimal($coordinate) if (!$dir || count($numbers[0]) < 3) return null; [$deg, $min, $sec] = array_map('floatval', $numbers[0]); + $decimal = $deg + ($min / 60) + ($sec / 3600); - if (in_array($dir[1], ['S', 'W'])) $decimal *= -1; + if (in_array($dir[1], ['S', 'W'])) { + $decimal *= -1; + } return $decimal; } @@ -78,25 +83,6 @@ public function store(Request $request) 'longitude' => 'required', 'foto_tps' => 'required|image|mimes:jpg,jpeg,png|max:2048', - ], [ - - 'kategori_tps_id.required' => 'Kategori TPS wajib dipilih.', - 'kategori_tps_id.exists' => 'Kategori TPS tidak valid.', - 'nama_tps.required' => 'Nama TPS wajib diisi.', - 'alamat_tps.required' => 'Alamat TPS wajib diisi.', - 'status_tps.required' => 'Status TPS wajib dipilih.', - 'status_tps.in' => 'Status TPS tidak valid.', - 'tahun_pembuatan.required' => 'Tahun pembuatan wajib diisi.', - 'tahun_pembuatan.digits' => 'Tahun pembuatan harus 4 digit.', - 'kapasitas_tps.required' => 'Kapasitas TPS wajib diisi.', - 'kapasitas_tps.integer' => 'Kapasitas TPS harus angka.', - 'kapasitas_tps.min' => 'Kapasitas minimal 1.', - 'latitude.required' => 'Latitude wajib diisi.', - 'longitude.required' => 'Longitude wajib diisi.', - 'foto_tps.required' => 'Foto TPS wajib diunggah.', - 'foto_tps.image' => 'Foto TPS harus berupa gambar.', - 'foto_tps.mimes' => 'Format foto harus jpg, jpeg, atau png.', - ]); if ($validator->fails()) { @@ -125,14 +111,8 @@ public function store(Request $request) if ($request->hasFile('foto_tps')) { - $file = $request->file('foto_tps'); - - $filename = strtolower(str_replace(' ', '_', $request->nama_tps)) - . '_' . time() . '.' . $file->getClientOriginalExtension(); - - $file->move(public_path('assets/admin/images/tps'), $filename); - - $foto = $filename; + $foto = $request->file('foto_tps') + ->store('tps', 'public'); } @@ -216,18 +196,12 @@ public function update(Request $request, $id) if ($request->hasFile('foto_tps')) { - if ($tps->foto_tps && file_exists(public_path('assets/admin/images/tps/' . $tps->foto_tps))) { - unlink(public_path('assets/admin/images/tps/' . $tps->foto_tps)); + if ($tps->foto_tps) { + Storage::disk('public')->delete($tps->foto_tps); } - $file = $request->file('foto_tps'); - - $filename = strtolower(str_replace(' ', '_', $request->nama_tps)) - . '_' . time() . '.' . $file->getClientOriginalExtension(); - - $file->move(public_path('assets/admin/images/tps'), $filename); - - $foto = $filename; + $foto = $request->file('foto_tps') + ->store('tps', 'public'); } @@ -256,19 +230,12 @@ public function destroy($id) $tps = LokasiTps::findOrFail($id); - $fotoPath = $tps->foto_tps - ? public_path('assets/admin/images/tps/' . $tps->foto_tps) - : null; - - - if ($fotoPath && file_exists($fotoPath)) { - unlink($fotoPath); + if ($tps->foto_tps) { + Storage::disk('public')->delete($tps->foto_tps); } - $tps->delete(); - return redirect()->route('admin.tps.index') ->with('success', 'Data TPS berhasil dihapus.'); } diff --git a/resources/views/admin/kategori-tps/edit.blade.php b/resources/views/admin/kategori-tps/edit.blade.php index c751bb4..89c4217 100644 --- a/resources/views/admin/kategori-tps/edit.blade.php +++ b/resources/views/admin/kategori-tps/edit.blade.php @@ -6,6 +6,7 @@
+
@@ -13,95 +14,126 @@

Form edit data kategori TPS

+ method="POST" + enctype="multipart/form-data"> + @csrf @method('PUT') {{-- NAMA KATEGORI --}}
+ + name="nama_kategori" + class="form-control @error('nama_kategori') is-invalid @enderror" + value="{{ old('nama_kategori', $kategori->nama_kategori) }}" + required> @error('nama_kategori') {{ $message }} @enderror
+ {{-- KEPANJANGAN --}}
+ + name="kepanjangan_kategori" + class="form-control @error('kepanjangan_kategori') is-invalid @enderror" + value="{{ old('kepanjangan_kategori', $kategori->kepanjangan_kategori) }}"> @error('kepanjangan_kategori') {{ $message }} @enderror
+ {{-- DESKRIPSI --}}
+ + rows="6" + class="form-control @error('deskripsi') is-invalid @enderror" + placeholder="Deskripsi">{{ old('deskripsi', $kategori->deskripsi) }} @error('deskripsi') {{ $message }} @enderror
+ {{-- FOTO --}}
+ - + + name="foto_kategori" + id="foto_kategori" + class="file-upload-default @error('foto_kategori') is-invalid @enderror" + accept="image/*"> +
+ + class="form-control file-upload-info" + disabled + placeholder="Upload Foto"> + - +
@error('foto_kategori') {{ $message }} @enderror - {{-- PREVIEW FOTO LAMA --}} + + {{-- PREVIEW FOTO --}} @if ($kategori->foto_kategori) -
- + +
+ + + + +
+ @endif +
- - Batal + + + + + Batal + +
+
diff --git a/resources/views/admin/kategori-tps/index.blade.php b/resources/views/admin/kategori-tps/index.blade.php index 11525ba..0d248aa 100644 --- a/resources/views/admin/kategori-tps/index.blade.php +++ b/resources/views/admin/kategori-tps/index.blade.php @@ -3,141 +3,197 @@ @section('title', 'Data Kategori TPS') @section('content') - + .table td { + vertical-align: top; + } + -
-
-
-
-
-
-
-

Data Kategori TPS

-

- Daftar Kategori Tempat Pembuangan Sampah (TPS) -

-
-
+
+
+
+
- -
- -
+
- - - Tambah - - -
+
+
+

Data Kategori TPS

+

+ Daftar Kategori Tempat Pembuangan Sampah (TPS) +

-
- - - - - - - - - - - @foreach ($kategori as $item) - - - - - - - @endforeach - -
Nama KategoriFotoDeskripsiAksi
{{ $item->nama_kategori }} - @if ($item->foto_kategori) - Foto Kategori - @else - - - @endif - -
- {{ $item->deskripsi ?? '-' }} -
-
- - - -
- @csrf - @method('DELETE') - -
-
+
+ + +
+ +
+ + + + Tambah + +
+
+ +
+ + + + + + + + + + + + + + + @forelse ($kategori as $item) + + + + + + + + + + + + + @empty + + + + + + @endforelse + + + +
Nama KategoriFotoDeskripsiAksi
+ {{ $item->nama_kategori }} + + @if ($item->foto_kategori) + + Foto Kategori + + @else + Tidak ada foto + @endif + +
+ {{ $item->deskripsi ?? '-' }} +
+
+ + + + + + + +
+ + @csrf + @method('DELETE') + + + +
+ +
+ Data kategori belum tersedia +
+ + +
+ {{ $kategori->links() }} +
+
+
+
- - @if (session('success')) - - @endif + }); + +}); + + + + +@if (session('success')) + + + +@endif + @endsection diff --git a/resources/views/admin/tps/edit.blade.php b/resources/views/admin/tps/edit.blade.php index 2c9d72c..bb41f7d 100644 --- a/resources/views/admin/tps/edit.blade.php +++ b/resources/views/admin/tps/edit.blade.php @@ -22,171 +22,166 @@ function decimalToDms($decimal, $type = 'lat') @section('title', 'Edit Data TPS') @section('content') -
-
-
-
-
+
+
+
+
+
-

Edit Data TPS

-

Form edit data Tempat Pembuangan Sampah

+

Edit Data TPS

+

Form edit data Tempat Pembuangan Sampah

-
- @csrf - @method('PUT') + - {{-- NAMA TPS --}} -
- - + @csrf + @method('PUT') - @error('nama_tps') - {{ $message }} - @enderror -
+
+ + - {{-- ALAMAT --}} -
- - - - @error('alamat_tps') - {{ $message }} - @enderror -
- - {{-- KATEGORI --}} -
- - - - @error('kategori_tps_id') - {{ $message }} - @enderror -
- - {{-- TAHUN --}} -
- - - - @error('tahun_pembuatan') - {{ $message }} - @enderror -
- - {{-- KAPASITAS --}} -
- - - - @error('kapasitas_tps') - {{ $message }} - @enderror -
- - {{-- STATUS --}} -
- - - - @error('status_tps') - {{ $message }} - @enderror -
- - {{-- LATITUDE --}} -
- - - - @error('latitude') - {{ $message }} - @enderror -
- - {{-- LONGITUDE --}} -
- - - - @error('longitude') - {{ $message }} - @enderror -
- - {{-- FOTO --}} -
- - - - -
- - - - + @error('nama_tps') + {{ $message }} + @enderror
- @error('foto_tps') - {{ $message }} - @enderror +
+ + - @if ($tps->foto_tps) -
- + @error('alamat_tps') + {{ $message }} + @enderror +
+ +
+ + + + @error('kategori_tps_id') + {{ $message }} + @enderror +
+ +
+ + + + @error('tahun_pembuatan') + {{ $message }} + @enderror +
+ +
+ + + + @error('kapasitas_tps') + {{ $message }} + @enderror +
+ +
+ + + + @error('status_tps') + {{ $message }} + @enderror +
+ +
+ + + + @error('latitude') + {{ $message }} + @enderror +
+ +
+ + + + @error('longitude') + {{ $message }} + @enderror +
+ +
+ + + + +
+ + + +
- @endif -
- - Batal - + @error('foto_tps') + {{ $message }} + @enderror + @if ($tps->foto_tps) +
+ +
+ @endif + +
+ + + Batal + + + +
-
@endsection diff --git a/resources/views/admin/tps/index.blade.php b/resources/views/admin/tps/index.blade.php index 43d7cec..b4e3d51 100644 --- a/resources/views/admin/tps/index.blade.php +++ b/resources/views/admin/tps/index.blade.php @@ -3,12 +3,14 @@ @section('title', 'Data TPS') @section('content') +
+ ```
@@ -60,8 +62,8 @@ class="form-control" placeholder="Cari nama TPS..."> @if ($item->foto_tps) - Foto TPS + Foto TPS @else - @endif @@ -121,8 +123,9 @@ class="btn btn-warning btn-sm me-1">
-
+ ``` +
- @if (session('success'))