81 lines
2.0 KiB
PHP
81 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Kriteria;
|
|
use App\Models\Alternatif;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class AlternatifController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$no = 1;
|
|
$mahasiswa = Auth::user()->id;
|
|
$alternatif = Alternatif::where('id_mahasiswa', $mahasiswa)->get();
|
|
$dosen = User::where('role', 'Dosen')->orderBy('name', 'ASC')->whereNotIn('name', Alternatif::where('id_mahasiswa', $mahasiswa)->pluck('nama'))->get();
|
|
$kriteria = Kriteria::get();
|
|
|
|
return view('alternatif', compact('no', 'mahasiswa', 'alternatif', 'dosen', 'kriteria'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'nama' => 'required',
|
|
'id_mahasiswa',
|
|
]);
|
|
|
|
$mahasiswa = Auth::user()->id;
|
|
|
|
Alternatif::create([
|
|
'nama' => $request->nama,
|
|
'id_mahasiswa' => $mahasiswa,
|
|
]);
|
|
|
|
return redirect('alternatif')->with('toast_success', 'Data Alternatif Berhasil Ditambahkan.');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$request->validate([
|
|
'nama' => 'required',
|
|
]);
|
|
|
|
$alternatif = Alternatif::find($id);
|
|
$alternatif->update($request->all());
|
|
|
|
return redirect('alternatif')->with('toast_success', 'Perubahan Berhasil Disimpan.');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$alternatif = Alternatif::find($id);
|
|
$alternatif->delete();
|
|
|
|
return redirect('alternatif')->with('toast_success', 'Data Alternatif Berhasil Dihapus.');
|
|
}
|
|
}
|