File: /home/posscale/public_html/printmanager/app/Filament/Resources/PrinterTypeResource.php
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PrinterTypeResource\Pages;
use App\Filament\Resources\PrinterTypeResource\RelationManagers;
use App\Models\Make;
use App\Models\Models;
use App\Models\PrinterType;
use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Closure;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Livewire\Component as Livewire;
class PrinterTypeResource extends Resource
{
use Forms\Concerns\InteractsWithForms;
protected static ?string $model = PrinterType::class;
protected static ?string $navigationIcon = 'heroicon-o-printer';
protected static ?string $navigationGroup = "Defaults";
protected static ?int $navigationSort = 3;
public static function shouldRegisterNavigation(): bool
{
return false; // hides from sidebar navigation
}
public static function canViewAny(): bool
{
if (app()->request->getHost() === env('APP_CENTRAL_DOMAIN')) {
return true;
}
return false;
}
public static function form(Form $form): Form
{
return $form
->schema([
Select::make('make_id')
->live()
->required()
->label('Make')
// ->dehydrated(false)
->options(Make::pluck('name', 'id'))
->afterStateUpdated(function (callable $set) {
$set('model_id', null);
}),
Select::make('model_id')
->label('Models')
->placeholder(fn(Forms\Get $get): string => empty($get('make_id')) ? 'Select model' : 'Select an option')
->options(function (Forms\Get $get) {
return Models::where('make_id', $get('make_id'))->pluck('name', 'id');
}),
TextInput::make('type_title')->helperText("This is for the infomation"),
Select::make('toner_type')->label('Select toner')
->options(['black', 'cyan', 'magenta', 'yellow']),
TextInput::make('drum_unit'),
TextInput::make('fuser_unit'),
TextInput::make('paper_tray'),
TextInput::make('paper_feed_rollers'),
TextInput::make('duplex_unit'),
TextInput::make('transfer_belt'),
TextInput::make('toner_discreptions'),
FileUpload::make('document'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('type_title')->sortable()->searchable(),
TextColumn::make('toner_type')->sortable(),
TextColumn::make('drum_unit')->sortable(),
TextColumn::make('fuser_unit')->sortable(),
TextColumn::make('paper_tray')->sortable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\ViewAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPrinterTypes::route('/'),
'create' => Pages\CreatePrinterType::route('/create'),
'edit' => Pages\EditPrinterType::route('/{record}/edit'),
'view' => Pages\ViewPrinterType::route('/{record}/view'),
];
}
}