You've already forked Atomcms-edit
153 lines
4.3 KiB
PHP
Executable File
153 lines
4.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Filament\Resources\RadioShouts;
|
|
|
|
use App\Filament\Resources\RadioShouts\Pages\ListRadioShouts;
|
|
use App\Models\RadioShout;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class RadioShoutResource extends Resource
|
|
{
|
|
#[\Override]
|
|
protected static ?string $model = RadioShout::class;
|
|
|
|
protected static ?bool $canCreate = false;
|
|
|
|
#[\Override]
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-chat-bubble-left-right';
|
|
|
|
#[\Override]
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Radio';
|
|
|
|
#[\Override]
|
|
protected static ?string $slug = 'radio/shouts';
|
|
|
|
#[\Override]
|
|
public static function getNavigationLabel(): string
|
|
{
|
|
return 'Shouts';
|
|
}
|
|
|
|
#[\Override]
|
|
public static function getModelLabel(): string
|
|
{
|
|
return 'Shout';
|
|
}
|
|
|
|
#[\Override]
|
|
public static function getPluralModelLabel(): string
|
|
{
|
|
return 'Shouts';
|
|
}
|
|
|
|
#[\Override]
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Section::make()
|
|
->schema([
|
|
Select::make('user_id')
|
|
->relationship('user', 'username')
|
|
->required()
|
|
->searchable()
|
|
->label('Gebruiker'),
|
|
|
|
Textarea::make('message')
|
|
->required()
|
|
->columnSpanFull()
|
|
->label('Bericht'),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
#[\Override]
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->defaultSort('id', 'desc')
|
|
->columns([
|
|
TextColumn::make('id')
|
|
->label('ID'),
|
|
|
|
TextColumn::make('user.username')
|
|
->label('Gebruiker'),
|
|
|
|
TextColumn::make('message')
|
|
->label('Bericht')
|
|
->limit(50),
|
|
|
|
IconColumn::make('reported')
|
|
->label('Gerapporteerd')
|
|
->boolean()
|
|
->trueIcon('heroicon-o-flag')
|
|
->falseIcon('heroicon-o-check')
|
|
->trueColor('danger')
|
|
->falseColor('success'),
|
|
|
|
TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->label('Aangemaakt'),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Action::make('report')
|
|
->label('Melden')
|
|
->icon('heroicon-o-flag')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->action(function (RadioShout $record) {
|
|
$record->update([
|
|
'reported' => true,
|
|
'reported_by' => auth()->id(),
|
|
]);
|
|
})
|
|
->hidden(fn (RadioShout $record) => $record->reported),
|
|
|
|
Action::make('unreport')
|
|
->label('Melding intrekken')
|
|
->icon('heroicon-o-check')
|
|
->color('success')
|
|
->requiresConfirmation()
|
|
->action(function (RadioShout $record) {
|
|
$record->update([
|
|
'reported' => false,
|
|
'reported_by' => null,
|
|
]);
|
|
})
|
|
->visible(fn (RadioShout $record) => $record->reported),
|
|
|
|
DeleteAction::make(),
|
|
])
|
|
->headerActions([]);
|
|
}
|
|
|
|
#[\Override]
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
#[\Override]
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListRadioShouts::route('/'),
|
|
];
|
|
}
|
|
}
|