<?php
namespace App\Http\Controllers;
use App\Models\kecamatan;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
class KecamatanController extends Controller
{
public function index()
{
$data['kecamatan'] = kecamatan::get();
return view('kecamatan.index')->with($data);
}
public function store(Request $request)
{
$request->validate(['name' => 'required']);
$data = ['name' => $request->name];
kecamatan::create($data);
return redirect()->route('kecamatan.index')->with('success', 'Data successfully added');
}
public function update(request $request, string $id)
{
try {
$decryptedId = Crypt::decryptString($id);
$request->validate(['name' => 'required']);
$data = ['name' => $request->name];
kecamatan::where('id', $decryptedId)->update($data);
return redirect()->route('kecamatan.index')->with('success', 'Data successfully changed');
} catch (DecryptException $e) {
return redirect()->back()->with('error', 'Invalid ID');
}
}
public function destroy(string $id)
{
try {
$decryptedId = Crypt::decryptString($id);
kecamatan::where('id', $decryptedId)->delete();
return redirect()->route('kecamatan.index')->with('delete', 'Data successfully deleted');
} catch (DecryptException $e) {
return redirect()->back()->with('error', 'Invalid ID');
}
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]