Added sticker detail resource page #26
293
app/Filament/Resources/StickerDetailResource.php
Normal file
293
app/Filament/Resources/StickerDetailResource.php
Normal file
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\StickerDetailExporter;
|
||||
use App\Filament\Imports\StickerDetailImporter;
|
||||
use App\Filament\Resources\StickerDetailResource\Pages;
|
||||
use App\Filament\Resources\StickerDetailResource\RelationManagers;
|
||||
use App\Models\StickerDetail;
|
||||
use App\Models\StickerStructureDetail;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
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 StickerDetailResource extends Resource
|
||||
{
|
||||
protected static ?string $model = StickerDetail::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Customized Sticker Printing';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('sticker_structure_detail_id')
|
||||
->label('Sticker ID')
|
||||
->relationship('stickerStructureDetail', 'sticker_id')
|
||||
->options(function (callable $get) {
|
||||
return StickerStructureDetail::pluck('sticker_id', 'id');
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\Select::make('design_element_type')
|
||||
->label('Design Element Type')
|
||||
->options([
|
||||
'Text' => 'Text',
|
||||
'Shape' => 'Shape',
|
||||
'Image' => 'Image',
|
||||
'QR' => 'QR',
|
||||
]),
|
||||
Forms\Components\TextInput::make('element_id')
|
||||
->label('Element ID'),
|
||||
Forms\Components\Select::make('element_type')
|
||||
->label('Element Type')
|
||||
->options([
|
||||
'Static' => 'Static',
|
||||
'Dynamic' => 'Dynamic',
|
||||
]),
|
||||
Forms\Components\TextInput::make('string_size')
|
||||
->label('String Size'),
|
||||
Forms\Components\TextInput::make('element_colour')
|
||||
->label('Element Colour'),
|
||||
Forms\Components\TextInput::make('string_align')
|
||||
->label('String Align'),
|
||||
Forms\Components\TextInput::make('string_x_value')
|
||||
->label('String X Value'),
|
||||
Forms\Components\TextInput::make('string_y_value')
|
||||
->label('String Y Value'),
|
||||
Forms\Components\Select::make('shape_name')
|
||||
->label('Shape Name')
|
||||
->options([
|
||||
'Line' => 'Line',
|
||||
'Rectangle' => 'Rectangle',
|
||||
]),
|
||||
Forms\Components\TextInput::make('shape_pen_size')
|
||||
->label('Shape Pen Size'),
|
||||
Forms\Components\TextInput::make('shape_x1_value')
|
||||
->label('Shape X1 Value'),
|
||||
Forms\Components\TextInput::make('shape_y1_value')
|
||||
->label('Shape Y1 Value'),
|
||||
Forms\Components\TextInput::make('shape_x2_value')
|
||||
->label('Shape X2 Value'),
|
||||
Forms\Components\TextInput::make('shape_y2_value')
|
||||
->label('Shape Y2 Value'),
|
||||
Forms\Components\FileUpload::make('image_path')
|
||||
->label('Image')
|
||||
->image()
|
||||
->directory('sticker-images')
|
||||
->visibility('public')
|
||||
->preserveFilenames(false)
|
||||
->required(false),
|
||||
Forms\Components\TextInput::make('image_type')
|
||||
->label('Image Type'),
|
||||
Forms\Components\TextInput::make('image_x')
|
||||
->label('Image X'),
|
||||
Forms\Components\TextInput::make('image_y')
|
||||
->label('Image Y'),
|
||||
Forms\Components\TextInput::make('image_width')
|
||||
->label('Image Width'),
|
||||
Forms\Components\TextInput::make('image_height')
|
||||
->label('Image Height'),
|
||||
Forms\Components\TextInput::make('qr_value')
|
||||
->label('QR Value'),
|
||||
Forms\Components\TextInput::make('qr_align')
|
||||
->label('QR Align'),
|
||||
Forms\Components\TextInput::make('qr_size')
|
||||
->label('QR Size'),
|
||||
Forms\Components\TextInput::make('qr_x_value')
|
||||
->label('QR X Value'),
|
||||
Forms\Components\TextInput::make('qr_y_value')
|
||||
->label('QR Y Value'),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->label('created_by')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
Forms\Components\Hidden::make('updated_by')
|
||||
->label('updated_by')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('No.')
|
||||
->label('No.')
|
||||
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
|
||||
$paginator = $livewire->getTableRecords();
|
||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('stickerStructureDetail.sticker_id')
|
||||
->label('Sticker ID')
|
||||
->sortable()
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('design_element_type')
|
||||
->label('Design Element Type')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('element_id')
|
||||
->label('Element ID')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('element_type')
|
||||
->label('Element Type')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('string_value')
|
||||
->label('String Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('string_font')
|
||||
->label('String Font')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('string_size')
|
||||
->label('String Size')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('element_colour')
|
||||
->label('Element Colour')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('string_align')
|
||||
->label('String Align')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('string_x_value')
|
||||
->label('String X Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('string_y_value')
|
||||
->label('String Y Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('shape_name')
|
||||
->label('Shape Name')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('shape_pen_size')
|
||||
->label('Shape Pen Size')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('shape_x1_value')
|
||||
->label('Shape X1 Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('shape_y1_value')
|
||||
->label('Shape Y1 Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('shape_x2_value')
|
||||
->label('Shape X2 Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('shape_y2_value')
|
||||
->label('Shape Y2 Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('image_path')
|
||||
->label('Image Path')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('image_type')
|
||||
->label('Image Type')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('image_x')
|
||||
->label('Image X')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('image_y')
|
||||
->label('Image Y')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('image_width')
|
||||
->label('Image Width')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('image_height')
|
||||
->label('Image Height')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('qr_value')
|
||||
->label('QR Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('qr_align')
|
||||
->label('QR Align')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('qr_size')
|
||||
->label('QR Size')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('qr_x_value')
|
||||
->label('QR X Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('qr_y_value')
|
||||
->label('QR Y Value')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('created_by')
|
||||
->label('Created By')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->label('Import Sticker Details')
|
||||
->color('warning')
|
||||
->importer(StickerDetailImporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import sticker details');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Sticker Details')
|
||||
->color('warning')
|
||||
->exporter(StickerDetailExporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export sticker details');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListStickerDetails::route('/'),
|
||||
'create' => Pages\CreateStickerDetail::route('/create'),
|
||||
'view' => Pages\ViewStickerDetail::route('/{record}'),
|
||||
'edit' => Pages\EditStickerDetail::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StickerDetailResource\Pages;
|
||||
|
||||
use App\Filament\Resources\StickerDetailResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateStickerDetail extends CreateRecord
|
||||
{
|
||||
protected static string $resource = StickerDetailResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StickerDetailResource\Pages;
|
||||
|
||||
use App\Filament\Resources\StickerDetailResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditStickerDetail extends EditRecord
|
||||
{
|
||||
protected static string $resource = StickerDetailResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StickerDetailResource\Pages;
|
||||
|
||||
use App\Filament\Resources\StickerDetailResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListStickerDetails extends ListRecords
|
||||
{
|
||||
protected static string $resource = StickerDetailResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StickerDetailResource\Pages;
|
||||
|
||||
use App\Filament\Resources\StickerDetailResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewStickerDetail extends ViewRecord
|
||||
{
|
||||
protected static string $resource = StickerDetailResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user