admin update, siswa update
This commit is contained in:
parent
c6e706c4e1
commit
40058c47cd
|
|
@ -45,32 +45,10 @@ public function store(Request $request)
|
|||
'nama_kelas.unique' => 'Nama kelas sudah ada di tingkat ini!',
|
||||
]);
|
||||
|
||||
|
||||
// Tentukan prefix berdasarkan tingkat
|
||||
if ($validated['tingkat'] == 'X') {
|
||||
$prefix = '10';
|
||||
} elseif ($validated['tingkat'] == 'XI') {
|
||||
$prefix = '11';
|
||||
} else {
|
||||
$prefix = '12';
|
||||
}
|
||||
|
||||
// Cari id terakhir berdasarkan prefix
|
||||
$last = Kelas::where('id_kelas', 'like', $prefix.'%')
|
||||
->orderBy('id_kelas', 'desc')
|
||||
->first();
|
||||
|
||||
if ($last) {
|
||||
$newId = $last->id_kelas + 1;
|
||||
} else {
|
||||
$newId = $prefix . '01';
|
||||
}
|
||||
|
||||
Kelas::create([
|
||||
'id_kelas' => $newId,
|
||||
'nama_kelas' => $validated['nama_kelas'],
|
||||
'tingkat' => $validated['tingkat'],
|
||||
]);
|
||||
Kelas::create([
|
||||
'nama_kelas' => $validated['nama_kelas'],
|
||||
'tingkat' => $validated['tingkat'],
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.kelas.index')
|
||||
->with('success', 'Data kelas berhasil ditambahkan!');
|
||||
|
|
|
|||
|
|
@ -42,50 +42,58 @@ public function index(Request $request)
|
|||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'nama_mapel' => 'required|string|max:100',
|
||||
], [
|
||||
'nama_mapel.required' => 'Nama mata pelajaran wajib diisi',
|
||||
]);
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'nama_mapel' => 'required|string|max:100',
|
||||
'kelas' => 'nullable|array'
|
||||
]);
|
||||
|
||||
// Auto-generate id_mapel
|
||||
$lastMapel = Mapel::orderBy('id_mapel', 'desc')->first();
|
||||
|
||||
if ($lastMapel) {
|
||||
$lastNumber = (int) substr($lastMapel->id_mapel, 2); // Ambil angka setelah "MP"
|
||||
$newNumber = $lastNumber + 1;
|
||||
} else {
|
||||
$newNumber = 1;
|
||||
$mapel = Mapel::create([
|
||||
'nama_mapel' => $validated['nama_mapel'],
|
||||
]);
|
||||
|
||||
if($request->kelas){
|
||||
foreach($request->kelas as $kelas){
|
||||
$mapel->mengajars()->create([
|
||||
'id_kelas' => $kelas
|
||||
]);
|
||||
}
|
||||
|
||||
$newIdMapel = 'MP' . str_pad($newNumber, 3, '0', STR_PAD_LEFT); // MP001, MP002, dst
|
||||
|
||||
Mapel::create([
|
||||
'id_mapel' => $newIdMapel,
|
||||
'nama_mapel' => $validated['nama_mapel'],
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.mapel.index')
|
||||
->with('success', 'Data mata pelajaran berhasil ditambahkan!');
|
||||
}
|
||||
|
||||
return redirect()->route('admin.mapel.index')
|
||||
->with('success','Data mata pelajaran berhasil ditambahkan!');
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, $id_mapel)
|
||||
{
|
||||
$mapel = Mapel::findOrFail($id_mapel);
|
||||
{
|
||||
$mapel = Mapel::findOrFail($id_mapel);
|
||||
|
||||
$validated = $request->validate([
|
||||
'nama_mapel' => 'required|string|max:100',
|
||||
], [
|
||||
'nama_mapel.required' => 'Nama mata pelajaran wajib diisi',
|
||||
]);
|
||||
$validated = $request->validate([
|
||||
'nama_mapel' => 'required|string|max:100',
|
||||
'kelas' => 'nullable|array'
|
||||
]);
|
||||
|
||||
$mapel->update($validated);
|
||||
$mapel->update([
|
||||
'nama_mapel' => $validated['nama_mapel']
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.mapel.index')
|
||||
->with('success', 'Data mata pelajaran berhasil diupdate!');
|
||||
// hapus relasi lama
|
||||
$mapel->mengajars()->delete();
|
||||
|
||||
// buat relasi baru
|
||||
if($request->kelas){
|
||||
foreach($request->kelas as $kelas){
|
||||
$mapel->mengajars()->create([
|
||||
'id_kelas' => $kelas
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->route('admin.mapel.index')
|
||||
->with('success','Data mata pelajaran berhasil diupdate!');
|
||||
}
|
||||
|
||||
public function destroy($id_mapel)
|
||||
{
|
||||
$mapel = Mapel::findOrFail($id_mapel);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ class Mapel extends Model
|
|||
protected $keyType = 'int';
|
||||
|
||||
protected $fillable = [
|
||||
'id_mapel',
|
||||
'nama_mapel',
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -225,11 +225,26 @@
|
|||
@error('nama_mapel')
|
||||
<small class="text-danger">{{ $message }}</small>
|
||||
@enderror
|
||||
<small class="text-muted">ID Mapel akan dibuat otomatis (MP001, MP002, ...)</small>
|
||||
<small class="text-muted">ID Mapel akan dibuat secara otomatis</small>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Kelas</label>
|
||||
|
||||
<select name="kelas[]" class="form-select" multiple>
|
||||
@foreach($kelass as $kelas)
|
||||
<option value="{{ $kelas->id_kelas }}">
|
||||
{{ $kelas->tingkat }} - {{ $kelas->nama_kelas }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
<small class="text-muted">Bisa pilih lebih dari satu kelas</small>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
||||
<button class="btn btn-success">Simpan Data</button>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@extends('layouts.siswa.app')
|
||||
@extends('siswa.layouts.app')
|
||||
|
||||
@section('title', 'Materi')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@extends('layouts.siswa.app')
|
||||
@extends('siswa.layouts.app')
|
||||
|
||||
@section('title', 'Materi - ' . optional(optional($mengajar)->mapel)->nama_mapel)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@extends('layouts.siswa.app')
|
||||
@extends('siswa.layouts.app')
|
||||
|
||||
@section('title', 'Tugas')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@extends('layouts.siswa.app')
|
||||
@extends('siswa.layouts.app')
|
||||
|
||||
@section('title', $tugas->judul_tugas)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@
|
|||
//SISWA CONTROLLERS
|
||||
use App\Http\Controllers\Siswa\LoginController as SiswaLoginController;
|
||||
use App\Http\Controllers\Siswa\DashboardController as SiswaDashboardController;
|
||||
use App\Http\Controllers\Siswa\MateriController as SiswaMateriController;
|
||||
use App\Http\Controllers\Siswa\TugasController as SiswaTugasController;
|
||||
|
||||
// ====================
|
||||
// LANDING PAGE
|
||||
|
|
@ -145,11 +147,19 @@
|
|||
// =======================================================
|
||||
// SISWA AREA
|
||||
// =======================================================
|
||||
|
||||
Route::middleware(['auth:siswa'])->prefix('siswa')->name('siswa.')->group(function () {
|
||||
|
||||
Route::get('/dashboard', [SiswaDashboardController::class, 'index'])->name('dashboard');
|
||||
|
||||
// MATERI
|
||||
Route::get('/materi', [SiswaMateriController::class, 'index'])->name('materi.index');
|
||||
Route::get('/materi/{id_mengajar}', [SiswaMateriController::class, 'show'])->name('materi.show');
|
||||
|
||||
// TUGAS
|
||||
Route::get('/tugas', [SiswaTugasController::class, 'index'])->name('tugas.index');
|
||||
Route::get('/tugas/{id_tugas}', [SiswaTugasController::class, 'show'])->name('tugas.show');
|
||||
Route::post('/tugas/{id_tugas}/submit', [SiswaTugasController::class, 'submit'])->name('tugas.submit');
|
||||
|
||||
// LOGOUT SISWA
|
||||
Route::post('/logout', [SiswaLoginController::class, 'logout'])->name('logout');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue