62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Pengumuman;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PengumumanController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$pengumuman = Pengumuman::latest()->get();
|
|
return view('admin.pengumuman.index', compact('pengumuman'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('admin.pengumuman.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'judul' => 'required|string|max:255',
|
|
'isi' => 'required|string',
|
|
'tanggal_mulai' => 'nullable|date',
|
|
'tanggal_selesai' => 'nullable|date|after_or_equal:tanggal_mulai',
|
|
'status' => 'boolean',
|
|
]);
|
|
|
|
Pengumuman::create($request->all());
|
|
|
|
return redirect()->route('pengumuman.index')->with('success', 'Pengumuman berhasil ditambahkan.');
|
|
}
|
|
|
|
public function edit(Pengumuman $pengumuman)
|
|
{
|
|
return view('admin.pengumuman.edit', compact('pengumuman'));
|
|
}
|
|
|
|
public function update(Request $request, Pengumuman $pengumuman)
|
|
{
|
|
$request->validate([
|
|
'judul' => 'required|string|max:255',
|
|
'isi' => 'required|string',
|
|
'tanggal_mulai' => 'nullable|date',
|
|
'tanggal_selesai' => 'nullable|date|after_or_equal:tanggal_mulai',
|
|
'status' => 'boolean',
|
|
]);
|
|
|
|
$pengumuman->update($request->all());
|
|
|
|
return redirect()->route('pengumuman.index')->with('success', 'Pengumuman berhasil diperbarui.');
|
|
}
|
|
|
|
public function destroy(Pengumuman $pengumuman)
|
|
{
|
|
$pengumuman->delete();
|
|
return redirect()->route('pengumuman.index')->with('success', 'Pengumuman berhasil dihapus.');
|
|
}
|
|
}
|