100 lines
3.1 KiB
PHP
100 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\CommentResource\Pages;
|
|
use App\Filament\Resources\CommentResource\RelationManagers;
|
|
use App\Models\Comment;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Components\RichEditor;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
class CommentResource extends Resource
|
|
{
|
|
protected static ?string $model = Comment::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-chat-bubble-bottom-center-text';
|
|
|
|
protected static ?string $navigationGroup = 'CMS';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Card::make()
|
|
->schema([
|
|
Select::make('news_id')
|
|
->relationship('news', 'title')
|
|
->required(),
|
|
TextInput::make('title')
|
|
->required()
|
|
->maxLength(255),
|
|
RichEditor::make('message')
|
|
->required()
|
|
->columnSpanFull(),
|
|
TextInput::make('author_name')
|
|
->label('Author Name (Optional)')
|
|
->maxLength(255),
|
|
])
|
|
->columns(2),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('news.title')
|
|
->label('News Article')
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('title')
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('author_name')
|
|
->label('Author')
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
Tables\Actions\DeleteAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListComments::route('/'),
|
|
'create' => Pages\CreateComment::route('/create'),
|
|
'edit' => Pages\EditComment::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|