public function table(Table $table): Table
{
return $table
->query(Message::query()
->where(function ($query) {
$query->where('role', null)
->where('department_id', null)
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->where('role', null)
->whereIn('department_id', Auth::user()->departments->pluck('id'))
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->whereIn('role', Auth::user()->roles->pluck('tag'))
->where('department_id', null)
->where('date', '<=', today());
})
->orWhere(function ($query) {
$query->whereIn('role', Auth::user()->roles->pluck('tag'))
->whereIn('department_id', Auth::user()->departments->pluck('id'))
->where('date', '<=', today());
})
)
->deferLoading()
->defaultSort('updated_at', 'desc')
->defaultPaginationPageOption(10)
->paginated([10])
->columns([
Split::make([
TextColumn::make('date')
->label(__('common.date'))
->date()
->color('gray')
->grow(false),
TextColumn::make('title')
->label(__('common.title'))
->searchable()
->weight(FontWeight::Bold)
->limit(50),
])
])
->actions([
ViewAction::make()
->modalHeading(fn (Message $record) => ($record->title))
->infolist(Message::getInfolist())
->slideOver(),
]);
}