Add all files
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\CustomPages\Admin\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
use Paymenter\Extensions\Others\CustomPages\Admin\Resources\CustomPagesResource\Pages;
|
||||
use Paymenter\Extensions\Others\CustomPages\Models\Page;
|
||||
|
||||
class CustomPagesResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Page::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-m-newspaper';
|
||||
|
||||
protected static ?string $navigationGroup = 'Custom Pages';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label('Title')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
|
||||
if (($get('slug') ?? '') !== Str::slug($old)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$set('slug', Str::slug($state));
|
||||
})
|
||||
->placeholder('Fill in the title for your page'),
|
||||
|
||||
Forms\Components\TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('URL-friendly slug for the page, e.g. about-us'),
|
||||
|
||||
Forms\Components\DateTimePicker::make('expires_at')
|
||||
->label('Expires at')
|
||||
->placeholder('Optional expiration date')
|
||||
->nullable()
|
||||
->helperText('If set, the page will become unavailable after this date.'),
|
||||
|
||||
Forms\Components\Select::make('visibility')
|
||||
->label('Visibility')
|
||||
->options([
|
||||
'everyone' => 'Everyone',
|
||||
'guests' => 'Only people who are not logged in',
|
||||
'logged-in' => 'Everyone who is logged in',
|
||||
'customers' => 'Customers only',
|
||||
'admins' => 'Admins only',
|
||||
])
|
||||
->default('everyone')
|
||||
->required()
|
||||
->helperText('Choose who can see your page'),
|
||||
|
||||
Toggle::make('is_active')
|
||||
->label('Published')
|
||||
->default(true)
|
||||
->helperText('Toggle if the page is enabled'),
|
||||
|
||||
Toggle::make('visible_in_menu')
|
||||
->label('Visible in navigationbar')
|
||||
->helperText('Toggle if the page is shown in the navigationbar'),
|
||||
|
||||
Forms\Components\MarkdownEditor::make('content')
|
||||
->label('Content')
|
||||
->required()
|
||||
->columnSpanFull()
|
||||
->placeholder('Enter the content of the page (supports markdown)'),
|
||||
Forms\Components\Section::make('Metadata')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('meta_title')
|
||||
->label('Meta Title')
|
||||
->placeholder('Custom title for SEO and embeds'),
|
||||
|
||||
Forms\Components\Textarea::make('meta_description')
|
||||
->label('Meta Description')
|
||||
->placeholder('Short description of the page'),
|
||||
|
||||
Forms\Components\ColorPicker::make('meta_color')
|
||||
->label('Meta Color')
|
||||
->placeholder('#ff6600'),
|
||||
|
||||
Forms\Components\FileUpload::make('meta_image')
|
||||
->label('Meta Image')
|
||||
->image()
|
||||
->directory('meta-images'),
|
||||
|
||||
Forms\Components\FileUpload::make('meta_favicon')
|
||||
->label('Meta Favicon')
|
||||
->image()
|
||||
->directory('meta-favicons'),
|
||||
])
|
||||
->columns(2)
|
||||
->collapsible()
|
||||
->collapsed(),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('slug')
|
||||
->label('Slug')
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('visibility')
|
||||
->label('Visibility')
|
||||
->sortable()
|
||||
->formatStateUsing(fn ($state) => ucfirst($state)),
|
||||
|
||||
Tables\Columns\IconColumn::make('is_active')
|
||||
->label('Active')
|
||||
->boolean()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\IconColumn::make('visible_in_menu')
|
||||
->label('On navigationbar')
|
||||
->boolean()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Last updated')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('views_count')
|
||||
->label('Views')
|
||||
->getStateUsing(fn (Page $record) => $record->views()->count())
|
||||
->sortable(),
|
||||
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCustomPages::route('/'),
|
||||
'create' => Pages\CreateCustomPages::route('/create'),
|
||||
'edit' => Pages\EditCustomPages::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user