Files
YNWA Fawzy fd6ff90988 first beta release.v3-pre
version 3 to match with filament and liveware release number.
2023-12-06 12:01:31 +04:00

113 lines
3.5 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Enums\StatusEnum;
use App\Filament\Resources\StoreResource\Pages;
use App\Filament\Resources\StoreResource\RelationManagers;
use App\Models\Store;
use Filament\Forms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\SelectColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Livewire\Attributes\Layout;
class StoreResource extends Resource
{
protected static ?string $model = Store::class;
protected static ?string $navigationIcon = 'heroicon-o-building-storefront';
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name'),
TextInput::make('domain')
->hidden(),
Select::make('currency')
->relationship('currency' , 'code')
->native(false)
->hiddenOn(['create', 'edit']),
Select::make('status')
->label('Status')
->hint('This will effect ALL the products that are related to this service')
->options(StatusEnum::to_array())
->default(StatusEnum::Published)
->preload()
->native(false),
Forms\Components\Section::make('settings')
->columns(4)
->schema([
Forms\Components\Toggle::make('tabs')
->inline(false)
->label('Display As Tab on Products'),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
ImageColumn::make('image')->disk('store')->height(50),
TextColumn::make('name')->searchable(),
SelectColumn::make('status')->options(StatusEnum::to_array()),
ToggleColumn::make('tabs')
])
->filters([
Tables\Filters\SelectFilter::make('status')
->options(StatusEnum::to_array())
->label('Status')
->native(false),
])->filtersLayout(Tables\Enums\FiltersLayout::AboveContent)
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}
public static function getRelations(): array
{
return [
RelationManagers\ProductsRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListStores::route('/'),
'create' => Pages\CreateStore::route('/create'),
'edit' => Pages\EditStore::route('/{record}/edit'),
];
}
}