Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Support\Prototype\Sample;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PengumumanController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
return view('pengumuman.index', ['items' => $this->visible()]);
|
||||
}
|
||||
|
||||
public function show(int $id): View
|
||||
{
|
||||
$item = $this->visible()->firstWhere('id', $id);
|
||||
abort_if($item === null, 404);
|
||||
|
||||
return view('pengumuman.show', ['item' => $item]);
|
||||
}
|
||||
|
||||
/** Pengumuman terbit yang ditujukan ke semua pengguna atau ke role pengguna ini. @return Collection<int, array<string, mixed>> */
|
||||
private function visible(): Collection
|
||||
{
|
||||
$audience = ['Semua pengguna', auth()->user()->role->label()];
|
||||
|
||||
return Sample::pengumuman()
|
||||
->where('status', 'Terbit')
|
||||
->filter(fn (array $item): bool => in_array($item['audiens'], $audience, true))
|
||||
->sortByDesc('tanggal')
|
||||
->values();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user