Menambahkan routing dan view untuk siswa
This commit is contained in:
commit
9965132e61
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SiswaController extends Controller
|
||||
{
|
||||
private $siswas = [];
|
||||
|
||||
public function index()
|
||||
{
|
||||
$siswas = session('siswas', []);
|
||||
return view('siswa.index', compact('siswas'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('siswa.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'nama' => 'required',
|
||||
'kelas' => 'required',
|
||||
'absen' => 'required|integer',
|
||||
]);
|
||||
|
||||
$siswaBaru = [
|
||||
'nama' => $request->nama,
|
||||
'kelas' => $request->kelas,
|
||||
'absen' => $request->absen,
|
||||
];
|
||||
|
||||
$siswas = session('siswas', []);
|
||||
$siswas[] = $siswaBaru;
|
||||
session(['siswas' => $siswas]);
|
||||
|
||||
return redirect()->route('siswa.index')->with('success', 'Data berhasil ditambahkan!');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$siswas = session('siswas', []);
|
||||
if (!isset($siswas[$id])) {
|
||||
return redirect()->route('siswa.index')->with('error', 'Data tidak ditemukan');
|
||||
}
|
||||
$siswa = $siswas[$id];
|
||||
|
||||
return view('siswa.edit', compact('siswa', 'id'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'nama' => 'required',
|
||||
'kelas' => 'required',
|
||||
'absen' => 'required|integer',
|
||||
]);
|
||||
|
||||
$siswas = session('siswas', []);
|
||||
if (!isset($siswas[$id])) return redirect()->route('siswa.index')->with('error', 'Data tidak ditemukan');
|
||||
|
||||
$siswas[$id] = [
|
||||
'nama' => $request->nama,
|
||||
'kelas' => $request->kelas,
|
||||
'absen' => $request->absen,
|
||||
];
|
||||
|
||||
session(['siswas' => $siswas]);
|
||||
|
||||
return redirect()->route('siswa.index')->with('success', 'Data berhasil diperbarui!');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$siswas = session('siswas', []);
|
||||
if (!isset($siswas[$id])) return redirect()->route('siswa.index')->with('error', 'Data tidak ditemukan');
|
||||
|
||||
unset($siswas[$id]);
|
||||
session(['siswas' => $siswas]);
|
||||
|
||||
return redirect()->route('siswa.index')->with('success', 'Data berhasil dihapus!');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Tambahkan Data Siswa</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
}
|
||||
body {
|
||||
background: linear-gradient(135deg, #b64fdb, #c7f0e1);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
width: 90%;
|
||||
max-width: 600px;
|
||||
background: #ffffff;
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
label {
|
||||
font-weight: 600;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #34495e;
|
||||
}
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #ddd;
|
||||
font-size: 16px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
input:focus {
|
||||
outline: none;
|
||||
border: 1px solid #3498db;
|
||||
box-shadow: 0 0 8px rgba(52,152,219,0.5);
|
||||
}
|
||||
.button {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: #b64fdb;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 50px;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.alert {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
padding: 15px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
border-left: 5px solid #f5c6cb;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h1>Tambahkan Data Siswa</h1>
|
||||
|
||||
@if($errors->any())
|
||||
<div class="alert">
|
||||
@foreach($errors->all() as $error)
|
||||
<p>{{ $error }}</p>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form action="{{ route('siswa.store') }}" method="POST">
|
||||
@csrf
|
||||
<label>Nama:</label>
|
||||
<input type="text" name="nama" required>
|
||||
|
||||
<label>Kelas:</label>
|
||||
<input type="text" name="kelas" required>
|
||||
|
||||
<label>Absen:</label>
|
||||
<input type="number" name="absen" required>
|
||||
|
||||
<button type="submit" class="button">Simpan Data</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,102 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Edit Data Siswa</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
}
|
||||
body {
|
||||
background: linear-gradient(135deg, #b64fdb, #c7f0e1);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
width: 90%;
|
||||
max-width: 600px;
|
||||
background: #ffffff;
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
label {
|
||||
font-weight: 600;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #34495e;
|
||||
}
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #ddd;
|
||||
font-size: 16px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
input:focus {
|
||||
outline: none;
|
||||
border: 1px solid #3498db;
|
||||
box-shadow: 0 0 8px rgba(52,152,219,0.5);
|
||||
}
|
||||
.button {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 50px;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
.button:hover {
|
||||
background: #2980b9;
|
||||
}
|
||||
.alert {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
padding: 15px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
border-left: 5px solid #f5c6cb;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h1>Hapus Data Siswa</h1>
|
||||
|
||||
<form action="{{ route('siswa.destroy', $id) }}" method="POST">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
|
||||
<label>Nama:</label>
|
||||
<input type="text" name="nama" value="{{ $siswa['nama'] }}" required>
|
||||
|
||||
<label>Kelas:</label>
|
||||
<input type="text" name="kelas" value="{{ $siswa['kelas'] }}" required>
|
||||
|
||||
<Label>Absen:</label>
|
||||
<input type="number" name="absen" value="{{ $siswa['absen'] }}" required>
|
||||
|
||||
<button type="submit" class="button"></button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,100 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Edit Data Siswa</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
}
|
||||
body {
|
||||
background: linear-gradient(135deg, #b64fdb, #c7f0e1);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
width: 90%;
|
||||
max-width: 600px;
|
||||
background: #ffffff;
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
label {
|
||||
font-weight: 600;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #34495e;
|
||||
}
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #ddd;
|
||||
font-size: 16px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
input:focus {
|
||||
outline: none;
|
||||
border: 1px solid #b64fdb;
|
||||
box-shadow: 0 0 8px rgba(52,152,219,0.5);
|
||||
}
|
||||
.button {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: #b64fdb;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 50px;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.alert {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
padding: 15px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
border-left: 5px solid #f5c6cb;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h1>Edit Data Siswa</h1>
|
||||
|
||||
<form action="{{ route('siswa.update', $id) }}" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<label>Nama:</label>
|
||||
<input type="text" name="nama" value="{{ $siswa['nama'] }}" required>
|
||||
|
||||
<label>Kelas:</label>
|
||||
<input type="text" name="kelas" value="{{ $siswa['kelas'] }}" required>
|
||||
|
||||
<Label>Absen:</label>
|
||||
<input type="number" name="absen" value="{{ $siswa['absen'] }}" required>
|
||||
|
||||
<button type="submit" class="button">Update</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,150 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Data Siswa</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
}
|
||||
body {
|
||||
background: linear-gradient(135deg, #b64fdb, #ACB6E5);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #333;
|
||||
}
|
||||
.container {
|
||||
width: 90%;
|
||||
max-width: 900px;
|
||||
background: #ffffff;
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 14px 30px;
|
||||
margin-top: 20px;
|
||||
color: #ffffff;
|
||||
background: #bd7dd4;
|
||||
text-decoration: none;
|
||||
border-radius: 50px;
|
||||
font-weight: 600;
|
||||
transition: background 0.3s ease;
|
||||
}
|
||||
.button:hover {
|
||||
background: #ACB6E5;
|
||||
}
|
||||
.alert {
|
||||
padding: 15px;
|
||||
background-color: #d1f2eb;
|
||||
color: #117864;
|
||||
margin-bottom: 20px;
|
||||
border-left: 6px solid #1abc9c;
|
||||
border-radius: 8px;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
overflow: hidden;
|
||||
border-radius: 15px;
|
||||
}
|
||||
thead {
|
||||
background-color: #bd7dd4;
|
||||
color: white;
|
||||
}
|
||||
th, td {
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
border-bottom: 1px solid #e1e1e1;
|
||||
}
|
||||
tbody tr:nth-child(even) {
|
||||
background-color: #f4f9fd;
|
||||
}
|
||||
tbody tr:hover {
|
||||
background-color: #e1e6fc;
|
||||
}
|
||||
p {
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
font-size: 18px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.button-opsi {
|
||||
display: inline-block;
|
||||
padding: 10px 15px;
|
||||
margin-top: 2px;
|
||||
color: #ffffff;
|
||||
background: #b64fdb;
|
||||
text-decoration: none;
|
||||
border: none;
|
||||
border-radius: 15px;
|
||||
font-size: 14px;
|
||||
font family: 'Poppins', sans-serif;
|
||||
font-weight: 300;
|
||||
transition: background 0.3s ease;
|
||||
margin-right: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Data Siswa</h1>
|
||||
|
||||
@if(session('success'))
|
||||
<div class="alert">{{ session('success') }}</div>
|
||||
@endif
|
||||
|
||||
@if(count($siswas) > 0)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Nama</th>
|
||||
<th>Kelas</th>
|
||||
<th>Absen</th>
|
||||
<th>Opsi lainnya</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($siswas as $index => $siswa)
|
||||
<tr>
|
||||
<td>{{ $index + 1 }}</td>
|
||||
<td>{{ $siswa['nama'] }}</td>
|
||||
<td>{{ $siswa['kelas'] }}</td>
|
||||
<td>{{ $siswa['absen'] }}</td>
|
||||
<td>
|
||||
<a href="{{ route('siswa.edit', $index) }}" class="button-opsi">Edit</a>
|
||||
<form action="{{ route('siswa.destroy', $index) }}" method="POST" style="display: inline;">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="button-opsi">Hapus</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@else
|
||||
<p>Belum ada data siswa, soalnya kamu pkl.</p>
|
||||
@endif
|
||||
|
||||
<a href="{{ route('siswa.create') }}" class="button">+ Tambah Data Siswa</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\App\Http\Controllers\SiswaController;
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
});
|
||||
|
||||
Route::get('/about', function () {
|
||||
return view('about');
|
||||
});
|
||||
|
||||
// Route::get('/datasiswa', [], function () {
|
||||
// $siswas = session('siswas', []);
|
||||
// return view('siswa.index', compact('siswas'));
|
||||
// })->name('siswa.index');
|
||||
|
||||
// Route::get('/siswa/create', function () {
|
||||
// return view('siswa.create');
|
||||
// })->name('siswa.create');
|
||||
|
||||
// Route::post('/siswa', function (Request $request) {
|
||||
// $request->validate([
|
||||
// 'nama' => 'required|string|max:255',
|
||||
// 'kelas' => 'required|string|max:50',
|
||||
// 'absen' => 'required|integer'
|
||||
// ]);
|
||||
|
||||
// $siswas = session('siswas', []);
|
||||
// $siswas[] = [
|
||||
// 'nama' => $request->nama,
|
||||
// 'kelas' => $request->kelas,
|
||||
// 'absen' => $request->absen
|
||||
// ];
|
||||
// session(['siswas' => $siswas]);
|
||||
|
||||
// return redirect()->route('siswa.index')->with('success', 'Data siswa berhasil ditambahkan!');
|
||||
// })->name('siswa.store');
|
||||
|
||||
Route::get('/datasiswa', [App\Http\Controllers\SiswaController::class, 'index'])->name('siswa.index');
|
||||
Route::get('/siswa/create', [App\Http\Controllers\SiswaController::class, 'create'])->name('siswa.create');
|
||||
Route::post('/siswa', [App\Http\Controllers\SiswaController::class, 'store'])->name('siswa.store');
|
||||
|
||||
Route::get('/siswa/{id}/edit', [App\Http\Controllers\SiswaController::class, 'edit'])->name('siswa.edit');
|
||||
Route::put('/siswa/{id}', [App\Http\Controllers\SiswaController::class, 'update'])->name('siswa.update');
|
||||
|
||||
Route::delete('/siswa/{id}', [App\Http\Controllers\SiswaController::class, 'destroy'])->name('siswa.destroy');
|
||||
Route::get('/siswa/{id}', [App\Http\Controllers\SiswaController::class, 'show'])->name('siswa.show');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue