MIF_E31230910_MP-HRIS-WEB/app/Http/Controllers/PengumumanController.php

61 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\StorePengumumanRequest;
use App\Http\Requests\UpdatePengumumanRequest;
use App\Models\Pengumuman;
use Illuminate\Support\Facades\Auth;
class PengumumanController extends Controller
{
public function index()
{
$pengumuman = Pengumuman::with('pembuat')
->orderBy('tanggal', 'desc')
->paginate(10);
$title = 'Pengumuman';
return view('pengumuman.index', compact('pengumuman', 'title'));
}
public function create()
{
$title = 'Buat Pengumuman';
return view('pengumuman.create', compact('title'));
}
public function store(StorePengumumanRequest $request)
{
$data = $request->validated();
$data['dibuat_oleh'] = Auth::id();
Pengumuman::create($data);
return redirect()->route('pengumuman.index')
->with('success', 'Pengumuman berhasil ditambahkan.');
}
public function edit(Pengumuman $pengumuman)
{
$title = 'Edit Pengumuman';
return view('pengumuman.edit', compact('pengumuman', 'title'));
}
public function update(UpdatePengumumanRequest $request, Pengumuman $pengumuman)
{
$pengumuman->update($request->validated());
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.');
}
}