94 lines
2.7 KiB
PHP
94 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class BobotKriteriaController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$kriterias = DB::table('criterias')->get();
|
|
return view('author.bobot-kriteria', compact('kriterias'));
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
try {
|
|
$bobotKriteria = DB::table('criterias')
|
|
->where('id_criteria', $id)
|
|
->first();
|
|
|
|
if (!$bobotKriteria) {
|
|
return redirect()->route('bobot.kriteria')
|
|
->with('error', 'Data tidak ditemukan');
|
|
}
|
|
|
|
return view('author.bobot-kriteria-edit', compact('bobotKriteria'));
|
|
} catch (\Exception $e) {
|
|
return redirect()->route('bobot.kriteria')
|
|
->with('error', 'Error: ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
try {
|
|
$request->validate([
|
|
'kriteria' => 'required',
|
|
'bobot' => 'required|numeric|min:0|max:1'
|
|
]);
|
|
|
|
DB::table('criterias')
|
|
->where('id_criteria', $id)
|
|
->update([
|
|
'Kriteria' => $request->kriteria,
|
|
'Bobot' => $request->bobot
|
|
]);
|
|
|
|
return redirect()->route('bobot.kriteria')
|
|
->with('success', 'Data berhasil diupdate');
|
|
} catch (\Exception $e) {
|
|
return redirect()->back()
|
|
->with('error', 'Gagal mengupdate data: ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
try {
|
|
$request->validate([
|
|
'Kriteria' => 'required',
|
|
'Bobot' => 'required|numeric|min:0|max:1'
|
|
]);
|
|
|
|
DB::table('criterias')->insert([
|
|
'Kriteria' => $request->Kriteria,
|
|
'Bobot' => $request->Bobot
|
|
]);
|
|
|
|
return redirect()->route('bobot.kriteria')
|
|
->with('success', 'Kriteria berhasil ditambahkan');
|
|
} catch (\Exception $e) {
|
|
return redirect()->back()
|
|
->with('error', 'Gagal menambahkan kriteria: ' . $e->getMessage())
|
|
->withInput();
|
|
}
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
try {
|
|
DB::table('criterias')
|
|
->where('id_criteria', $id)
|
|
->delete();
|
|
|
|
return redirect()->route('bobot.kriteria')
|
|
->with('success', 'Data berhasil dihapus');
|
|
} catch (\Exception $e) {
|
|
return redirect()->route('bobot.kriteria')
|
|
->with('error', 'Gagal menghapus data: ' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|