70 lines
2.0 KiB
PHP
70 lines
2.0 KiB
PHP
<?php
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\InfoAngket;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class InfoAngketController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$infos = InfoAngket::all();
|
|
return view('admin.angket.info.index', compact('infos'))->with('success', session('success'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('admin.angket.info.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'tata_cara' => 'required',
|
|
]);
|
|
|
|
try {
|
|
InfoAngket::create($request->all());
|
|
return redirect()->route('admin.info.index')->with('success', 'Info berhasil ditambahkan');
|
|
} catch (\Exception $e) {
|
|
Log::error('Gagal menyimpan info angket: ' . $e->getMessage());
|
|
return back()->withInput()->withErrors('Gagal menyimpan info angket.');
|
|
}
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$info = InfoAngket::findOrFail($id);
|
|
return view('admin.angket.info.edit', compact('info'));
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$request->validate([
|
|
'tata_cara' => 'required',
|
|
]);
|
|
|
|
try {
|
|
$info = InfoAngket::findOrFail($id);
|
|
$info->update($request->all());
|
|
return redirect()->route('admin.info.index')->with('success', 'Info berhasil diubah');
|
|
} catch (\Exception $e) {
|
|
Log::error('Gagal memperbarui info angket: ' . $e->getMessage());
|
|
return back()->withInput()->withErrors('Gagal memperbarui info angket.');
|
|
}
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
try {
|
|
InfoAngket::destroy($id);
|
|
return back()->with('success', 'Info berhasil dihapus');
|
|
} catch (\Exception $e) {
|
|
Log::error('Gagal menghapus info angket: ' . $e->getMessage());
|
|
return back()->withErrors('Gagal menghapus info angket.');
|
|
}
|
|
}
|
|
}
|