<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\LokasiModel;

class LokasiController extends Controller
{
    public function index()
    {
        $data = LokasiModel::allLokasi();
        return view('dashboard.lokasi.lokasi', ['data' => $data]);
    }

    public function store(Request $request)
    {
        LokasiModel::create([
            'nama' => $request->nama,
            'lokasi' => $request->lokasi,
            'jenis' => $request->jenis,
        ]);

        return redirect()->route('lokasi')->with('success', 'Data Lokasi Berhasil Ditambahkan');
    }

    public function update(Request $request, $id_lokasi)
    {
        LokasiModel::where('id_lokasi', $id_lokasi)->update([
            'nama' => $request->nama,
            'lokasi' => $request->lokasi,
            'jenis' => $request->jenis,
        ]);

        return redirect()->route('lokasi')->with('success', 'Data Lokasi Berhasil Diupdate');
    }

    public function destroy(Request $request)
    {
        $id_lokasi = $request->input('id_lokasi');
        LokasiModel::where('id_lokasi', $id_lokasi)->delete();
        return redirect()->route('lokasi')->with('success', 'Data Lokasi Berhasil Dihapus');
    }
}
