CRUD Jurusan
This commit is contained in:
parent
ce4412bf2f
commit
44f26f1b5a
|
@ -8,7 +8,46 @@
|
|||
class JurusanController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
$jurusan = Jurusan::select('id', 'nama_jurusan')->get();
|
||||
return view('admin.jurusan', compact('jurusan'));
|
||||
$jurusan = Jurusan::all();
|
||||
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') }}"
|
||||
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><a href="{{ route('admin.jurusan') }}"
|
||||
class="block p-2 rounded-lg {{ request()->is('admin/jurusan') ? 'bg-blue-100 text-blue-600' : 'bg-gray-50 text-gray-800' }}">Jurusan</a>
|
||||
<li><a href="{{ route('admin.jurusan.index') }}"
|
||||
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><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>
|
||||
|
|
|
@ -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="flex justify-between items-center mb-4">
|
||||
<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
|
||||
</a>
|
||||
</div>
|
||||
|
@ -27,8 +27,8 @@
|
|||
<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 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>
|
||||
<form action="{{ route('siswa.destroy', $item->id) }}" method="POST" class="inline-block">
|
||||
<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('admin.jurusan.destroy', $item->id) }}" method="POST" class="inline-block">
|
||||
@csrf
|
||||
@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">
|
||||
|
@ -43,4 +43,4 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@endsection
|
|
@ -48,8 +48,14 @@
|
|||
Route::get('/kelas', [KelasController::class, 'index'])->name('admin.kelas');
|
||||
|
||||
// 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
|
||||
Route::get('/ruangan', [RuanganController::class, 'index'])->name('admin.ruangan');
|
||||
|
||||
|
|
Loading…
Reference in New Issue