139 lines
4.7 KiB
PHP
139 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\SolutionResource\Pages;
|
|
use App\Models\Solution;
|
|
use App\Models\UserRole;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Support\Str;
|
|
|
|
class SolutionResource extends Resource
|
|
{
|
|
protected static ?string $model = Solution::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-light-bulb';
|
|
|
|
protected static ?string $navigationGroup = 'Our Solutions';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\TextInput::make('title')
|
|
->required()
|
|
->maxLength(255)
|
|
->reactive()
|
|
->afterStateUpdated(fn (string $operation, $state, Forms\Set $set) => $operation === 'create' ? $set('slug', Str::slug($state)) : null)
|
|
->debounce('1000ms'),
|
|
|
|
Forms\Components\TextInput::make('slug')
|
|
->required()
|
|
->maxLength(255),
|
|
|
|
Forms\Components\TextInput::make('title_description')
|
|
->maxLength(255)
|
|
->required()
|
|
->columnSpanFull(),
|
|
|
|
Forms\Components\Repeater::make('bullets')
|
|
->schema([
|
|
Forms\Components\TextInput::make('bullet')
|
|
->label('Bullet Point')
|
|
->required(),
|
|
])
|
|
->columns(1)
|
|
->columnSpanFull()
|
|
->createItemButtonLabel('Add Bullet Point')
|
|
->defaultItems(1),
|
|
Forms\Components\Repeater::make('downloads')
|
|
->schema([
|
|
Forms\Components\TextInput::make('title')
|
|
->label('Download Title')
|
|
->required(false),
|
|
Forms\Components\FileUpload::make('file')
|
|
->label('Download File')
|
|
->required(false)
|
|
->disk('public')
|
|
->directory('solution-downloads'),
|
|
])
|
|
->columns(1)
|
|
->columnSpanFull()
|
|
->createItemButtonLabel('Add Download Item')
|
|
->defaultItems(1),
|
|
Forms\Components\Repeater::make('faqs')
|
|
->schema([
|
|
Forms\Components\TextInput::make('question')
|
|
->label('Question')
|
|
->required(),
|
|
Forms\Components\RichEditor::make('answer')
|
|
->label('Answer')
|
|
->required(),
|
|
])
|
|
->columns(1)
|
|
->columnSpanFull()
|
|
->createItemButtonLabel('Add FAQ')
|
|
->defaultItems(1),
|
|
Forms\Components\RichEditor::make('description')
|
|
->required()
|
|
->columnSpanFull(),
|
|
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('title')
|
|
->searchable(),
|
|
Tables\Columns\TextColumn::make('slug')
|
|
->searchable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListSolutions::route('/'),
|
|
'create' => Pages\CreateSolution::route('/create'),
|
|
'edit' => Pages\EditSolution::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function canViewAny(): bool
|
|
{
|
|
return auth()->user()->role === UserRole::ADMIN || auth()->user()->role === UserRole::MANAGER;
|
|
}
|
|
}
|