CRUD Jurusan
This commit is contained in:
parent
ce4412bf2f
commit
44f26f1b5a
|
@ -8,7 +8,46 @@
|
||||||
class JurusanController extends Controller
|
class JurusanController extends Controller
|
||||||
{
|
{
|
||||||
public function index(){
|
public function index(){
|
||||||
$jurusan = Jurusan::select('id', 'nama_jurusan')->get();
|
$jurusan = Jurusan::all();
|
||||||
return view('admin.jurusan', compact('jurusan'));
|
return view('admin.jurusan.index', compact('jurusan'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(){
|
||||||
|
return view('admin.jurusan.create');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request){
|
||||||
|
$request->validate([
|
||||||
|
'nama_jurusan' => 'required|string|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Jurusan::create([
|
||||||
|
'nama_jurusan' => $request->nama_jurusan , // Mengambil nama dari form
|
||||||
|
]);
|
||||||
|
return redirect()->route('admin.jurusan.index')->with('success', 'Jurusan berhasil ditambahkan');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(Jurusan $jurusan){
|
||||||
|
return view('admin.jurusan.edit', compact('jurusan'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, Jurusan $jurusan){
|
||||||
|
$request->validate([
|
||||||
|
'nama_jurusan' => 'required|string|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$jurusan->update([
|
||||||
|
'nama_jurusan' => $request->nama_jurusan,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect()->route('admin.jurusan.index')->with('success', 'Jurusan berhasil di update');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Menghapus jurusan
|
||||||
|
public function destroy(Jurusan $jurusan)
|
||||||
|
{
|
||||||
|
$jurusan->delete();
|
||||||
|
|
||||||
|
return redirect()->route('admin.jurusan.index')->with('success', 'Jurusan berhasil dihapus');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ class="block p-2 rounded-lg {{ request()->is('admin/guru') ? 'bg-blue-100 text-b
|
||||||
<li><a href="{{ route('admin.kelas') }}"
|
<li><a href="{{ route('admin.kelas') }}"
|
||||||
class="block p-2 rounded-lg {{ request()->is('admin/kelas') ? 'bg-blue-100 text-blue-600' : 'bg-gray-50 text-gray-800' }}">Kelas</a>
|
class="block p-2 rounded-lg {{ request()->is('admin/kelas') ? 'bg-blue-100 text-blue-600' : 'bg-gray-50 text-gray-800' }}">Kelas</a>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="{{ route('admin.jurusan') }}"
|
<li><a href="{{ route('admin.jurusan.index') }}"
|
||||||
class="block p-2 rounded-lg {{ request()->is('admin/jurusan') ? 'bg-blue-100 text-blue-600' : 'bg-gray-50 text-gray-800' }}">Jurusan</a>
|
class="block p-2 rounded-lg {{ request()->is('admin/jurusan/index') ? 'bg-blue-100 text-blue-600' : 'bg-gray-50 text-gray-800' }}">Jurusan</a>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="{{ route('admin.ruangan') }}"
|
<li><a href="{{ route('admin.ruangan') }}"
|
||||||
class="block p-2 rounded-lg {{ request()->is('admin/ruangan') ? 'bg-blue-100 text-blue-600' : 'bg-gray-50 text-gray-800' }}">Ruangan</a>
|
class="block p-2 rounded-lg {{ request()->is('admin/ruangan') ? 'bg-blue-100 text-blue-600' : 'bg-gray-50 text-gray-800' }}">Ruangan</a>
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
@extends('layouts.dashboard')
|
||||||
|
|
||||||
|
@section('title', 'Smart School | Tambah Jurusan')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
<div class="bg-white shadow-md rounded-lg p-6">
|
||||||
|
<h1 class="text-2xl font-semibold mb-4">Tambah Jurusan</h1>
|
||||||
|
|
||||||
|
<form action="{{ route('admin.jurusan.store') }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="nama_jurusan" class="block text-sm font-medium text-gray-700">Nama Jurusan</label>
|
||||||
|
<input type="text" id="nama_jurusan" name="nama_jurusan" class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" required>
|
||||||
|
@error('nama_jurusan')
|
||||||
|
<div class="text-red-500 text-sm mt-2">{{ $message }}</div>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">Simpan</button>
|
||||||
|
<a href="{{ route('admin.jurusan.index') }}" class="ml-4 text-gray-700 hover:text-gray-900">Kembali</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endsection
|
|
@ -0,0 +1,26 @@
|
||||||
|
@extends('layouts.dashboard')
|
||||||
|
|
||||||
|
@section('title', 'Smart School | Edit Jurusan')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
<div class="bg-white shadow-md rounded-lg p-6">
|
||||||
|
<h1 class="text-2xl font-semibold mb-4">Edit Jurusan</h1>
|
||||||
|
|
||||||
|
<form action="{{ route('admin.jurusan.update', $jurusan->id) }}" method="POST">
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="nama_jurusan" class="block text-sm font-medium text-gray-700">Nama Jurusan</label>
|
||||||
|
<input type="text" id="nama_jurusan" name="nama_jurusan" value="{{ old('nama_jurusan', $jurusan->nama_jurusan) }}" class="mt-1 block w-full px-4 py-2 border border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500" required>
|
||||||
|
@error('nama_jurusan')
|
||||||
|
<div class="text-red-500 text-sm mt-2">{{ $message }}</div>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">Update</button>
|
||||||
|
<a href="{{ route('admin.jurusan.index') }}" class="ml-4 text-gray-700 hover:text-gray-900">Kembali</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endsection
|
|
@ -7,7 +7,7 @@
|
||||||
<div class="bg-white shadow-md rounded-lg p-6">
|
<div class="bg-white shadow-md rounded-lg p-6">
|
||||||
<div class="flex justify-between items-center mb-4">
|
<div class="flex justify-between items-center mb-4">
|
||||||
<h1 class="text-2xl font-semibold">Data Jurusan</h1>
|
<h1 class="text-2xl font-semibold">Data Jurusan</h1>
|
||||||
<a href="{{ route('siswa.create') }}" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
|
<a href="{{ route('admin.jurusan.create') }}" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg">
|
||||||
+ Tambah Jurusan
|
+ Tambah Jurusan
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,8 +27,8 @@
|
||||||
<td class="border px-4 py-2">{{ $index + 1 }}</td>
|
<td class="border px-4 py-2">{{ $index + 1 }}</td>
|
||||||
<td class="border px-4 py-2">{{ $item->nama_jurusan }}</td>
|
<td class="border px-4 py-2">{{ $item->nama_jurusan }}</td>
|
||||||
<td class="border px-4 py-2 text-center">
|
<td class="border px-4 py-2 text-center">
|
||||||
<a href="{{ route('siswa.edit', $item->id) }}" class="bg-yellow-400 hover:bg-yellow-500 text-white px-3 py-1 rounded">Edit</a>
|
<a href="{{ route('admin.jurusan.edit', $item->id) }}" class="bg-yellow-400 hover:bg-yellow-500 text-white px-3 py-1 rounded">Edit</a>
|
||||||
<form action="{{ route('siswa.destroy', $item->id) }}" method="POST" class="inline-block">
|
<form action="{{ route('admin.jurusan.destroy', $item->id) }}" method="POST" class="inline-block">
|
||||||
@csrf
|
@csrf
|
||||||
@method('DELETE')
|
@method('DELETE')
|
||||||
<button type="submit" onclick="return confirm('Yakin ingin menghapus?')" class="bg-red-500 hover:bg-red-600 text-white px-3 py-1 rounded">
|
<button type="submit" onclick="return confirm('Yakin ingin menghapus?')" class="bg-red-500 hover:bg-red-600 text-white px-3 py-1 rounded">
|
|
@ -48,8 +48,14 @@
|
||||||
Route::get('/kelas', [KelasController::class, 'index'])->name('admin.kelas');
|
Route::get('/kelas', [KelasController::class, 'index'])->name('admin.kelas');
|
||||||
|
|
||||||
// Jurusan
|
// Jurusan
|
||||||
Route::get('/jurusan', [JurusanController::class, 'index'])->name('admin.jurusan');
|
Route::resource('jurusan', JurusanController::class)->names([
|
||||||
|
'index' => 'admin.jurusan.index',
|
||||||
|
'create' => 'admin.jurusan.create',
|
||||||
|
'store' => 'admin.jurusan.store',
|
||||||
|
'edit' => 'admin.jurusan.edit',
|
||||||
|
'update' => 'admin.jurusan.update',
|
||||||
|
'destroy' => 'admin.jurusan.destroy',
|
||||||
|
]);
|
||||||
// Ruangan
|
// Ruangan
|
||||||
Route::get('/ruangan', [RuanganController::class, 'index'])->name('admin.ruangan');
|
Route::get('/ruangan', [RuanganController::class, 'index'])->name('admin.ruangan');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue