Menambahkan HTTP Method Untuk Data Siswa

This commit is contained in:
Syifa 2025-07-21 15:40:31 +07:00
parent ee0597483d
commit c453e72bc8
5 changed files with 316 additions and 18 deletions

View File

@ -28,15 +28,18 @@ class SiswaController extends Controller
'absen' => 'required|integer', 'absen' => 'required|integer',
]); ]);
$siswaBaru = [ $siswas = session('siswas', []);
// Index mulai dari 1
$index = count($siswas) + 1;
$siswas[$index] = [
'nama' => $request->nama, 'nama' => $request->nama,
'kelas' => $request->kelas, 'kelas' => $request->kelas,
'umur' => $request->umur, 'umur' => $request->umur,
'absen' => $request->absen, 'absen' => $request->absen,
]; ];
$siswas = session('siswas', []);
$siswas[] = $siswaBaru;
session(['siswas' => $siswas]); session(['siswas' => $siswas]);
return redirect()->route('siswa.index')->with('success', 'Data berhasil ditambahkan!'); return redirect()->route('siswa.index')->with('success', 'Data berhasil ditambahkan!');
@ -73,4 +76,34 @@ class SiswaController extends Controller
return redirect()->route('siswa.index')->with('success', 'Data siswa berhasil diupdate!'); return redirect()->route('siswa.index')->with('success', 'Data siswa berhasil diupdate!');
} }
public function show($id)
{
$siswa = [
1 => [
'nama' => 'syifa',
'kelas' => 'XIII',
'umur' => 19,
'absen' => 34
],
2 => [
'nama' => 'cipa',
'kelas' => 'XIII SIJA A',
'umur' => 18,
'absen' => 35
]
];
// Jika data tidak ditemukan, tampilkan halaman khusus
if (!isset($siswa[$id])) {
return view('siswa.notfound', ['id' => $id]);
} }
return view('siswa.detail', [
'id' => $id,
'siswa' => $siswa[$id]
]);
}
}

View File

@ -0,0 +1,106 @@
<!DOCTYPE html>
<html>
<head>
<title>Data Siswa</title>
<style>
body {
background: linear-gradient(to bottom right, #92e2f2, #b0d9f8);
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
width: 80%;
margin: 50px auto;
background-color: white;
border-radius: 20px;
box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.15);
padding: 30px;
text-align: center;
}
h1 {
color: #2c3e50;
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
border-radius: 12px;
overflow: hidden;
}
th, td {
padding: 15px;
text-align: center;
}
th {
background-color: #3498db;
color: white;
}
tr:nth-child(even) {
background-color: #ecf6fd;
}
tr:nth-child(odd) {
background-color: #d9effb;
}
.btn {
background-color: #3498db;
color: white;
padding: 10px 18px;
border: none;
border-radius: 20px;
cursor: pointer;
font-weight: bold;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #2980b9;
}
.add-btn {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Data Siswa</h1>
<table>
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Kelas</th>
<th>Umur</th>
<th>Absen</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
@foreach ($siswa as $index => $item)
<tr>
<td>{{ $index + 1 }}</td>
<td>{{ $item->nama }}</td>
<td>{{ $item->kelas }}</td>
<td>{{ $item->umur }}</td>
<td>{{ $item->absen }}</td>
<td>
<a href="{{ url('/siswa/' . $item->id . '/edit') }}" class="btn">Edit</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<br>
<a href="{{ url('/siswa/create') }}" class="btn add-btn">+ Tambah Data Siswa</a>
</div>
</body>
</html>

View File

@ -0,0 +1,96 @@
<!DOCTYPE html>
<html>
<head>
<title>Data Siswa</title>
<style>
body {
background: linear-gradient(to bottom right, #92e2f2, #b0d9f8);
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
width: 80%;
margin: 50px auto;
background-color: white;
border-radius: 20px;
box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.15);
padding: 30px;
text-align: center;
}
h1 {
color: #2c3e50;
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
border-radius: 12px;
overflow: hidden;
}
th, td {
padding: 15px;
text-align: center;
}
th {
background-color: #3498db;
color: white;
}
tr:nth-child(even) {
background-color: #ecf6fd;
}
tr:nth-child(odd) {
background-color: #d9effb;
}
.btn {
background-color: #3498db;
color: white;
padding: 10px 18px;
border: none;
border-radius: 20px;
cursor: pointer;
font-weight: bold;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #2980b9;
}
.add-btn {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Data Siswa</h1>
<table>
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Kelas</th>
<th>Umur</th>
<th>Absen</th>
</tr>
<tr>
<td>{{ $id }}</td>
<td>{{ $siswa['nama'] }}</td>
<td>{{ $siswa['kelas'] }}</td>
<td>{{ $siswa['umur'] }}</td>
<td>{{ $siswa['absen'] }}</td>
</tr>
</table>
<br>
</div>
</body>
</html>

View File

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<title>Data Siswa Tidak Ditemukan</title>
<style>
body {
background: linear-gradient(to bottom right, #92e2f2, #b0d9f8);
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.text-center {
text-align: center;
margin-top: 50px;
}
h2 {
color: #2c3e50;
background-color: #ecf6fd;
padding: 20px;
border-radius: 15px;
display: inline-block;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.btn {
background-color: #3498db;
color: white;
padding: 10px 20px;
border: none;
border-radius: 25px;
text-decoration: none;
font-weight: bold;
transition: background-color 0.3s ease, transform 0.2s ease;
display: inline-block;
}
.btn:hover {
background-color: #2980b9;
transform: scale(1.05);
}
.mt-3 {
margin-top: 1rem;
}
.mt-5 {
margin-top: 3rem;
}
</style>
</head>
<body>
<div class="text-center mt-5">
<h2>Data siswa dengan ID {{ $id }} tidak ditemukan</h2>
<br>
<a href="{{ route('siswa.index') }}" class="btn mt-3">Kembali ke daftar siswa</a>
</div>
</body>
</html>

View File

@ -18,3 +18,6 @@ Route::post('/siswa', [SiswaController::class, 'store'])->name('siswa.store');
Route::get('/siswa/{id}/edit', [SiswaController::class, 'edit'])->name('siswa.edit'); Route::get('/siswa/{id}/edit', [SiswaController::class, 'edit'])->name('siswa.edit');
Route::put('/siswa/{id}', [SiswaController::class, 'update'])->name('siswa.update'); Route::put('/siswa/{id}', [SiswaController::class, 'update'])->name('siswa.update');
Route::get('/datasiswa/{id}', [SiswaController::class, 'show']);
Route::get('/datasiswa/{id}', [SiswaController::class, 'show'])->name('siswa.show');