Added guard_name resource files
This commit is contained in:
200
app/Filament/Resources/GuardNameResource.php
Normal file
200
app/Filament/Resources/GuardNameResource.php
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Exports\GuardNameExporter;
|
||||||
|
use App\Filament\Imports\GuardNameImporter;
|
||||||
|
use App\Filament\Resources\GuardNameResource\Pages;
|
||||||
|
use App\Filament\Resources\GuardNameResource\RelationManagers;
|
||||||
|
use App\Models\GuardName;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Forms\Get;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class GuardNameResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = GuardName::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
|
||||||
|
protected static ?string $navigationGroup = 'Master Entries';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 13;
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
Forms\Components\Select::make('plant_id')
|
||||||
|
->label('Plant')
|
||||||
|
->relationship('plant', 'name')
|
||||||
|
->required()
|
||||||
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
return optional(GuardName::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
if (!$plantId) {
|
||||||
|
$set('GnError', 'Please select a plant first.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$set('GnError', null);
|
||||||
|
$set('created_by', Filament::auth()->user()?->name);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->extraAttributes(fn ($get) => [
|
||||||
|
'class' => $get('GnError') ? 'border-red-500' : '',
|
||||||
|
])
|
||||||
|
->hint(fn ($get) => $get('GnError') ? $get('GnError') : null)
|
||||||
|
->hintColor('danger'),
|
||||||
|
Forms\Components\TextInput::make('name')
|
||||||
|
->label('Name')
|
||||||
|
->required()
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('created_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
|
->rule(function (callable $get) {
|
||||||
|
return Rule::unique('guard_names', 'name')
|
||||||
|
->where('plant_id', $get('plant_id'))
|
||||||
|
->ignore($get('id'));
|
||||||
|
}),
|
||||||
|
Forms\Components\TextInput::make('identification1')
|
||||||
|
->label('Identification-1')
|
||||||
|
->required()
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('created_by', Filament::auth()->user()?->name);
|
||||||
|
}),
|
||||||
|
Forms\Components\TextInput::make('identification2')
|
||||||
|
->label('Identification-2')
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('created_by', Filament::auth()->user()?->name);
|
||||||
|
}),
|
||||||
|
Forms\Components\Hidden::make('created_by')
|
||||||
|
->default(fn () => Filament::auth()->user()?->name)
|
||||||
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('id')
|
||||||
|
->hidden()
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('created_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
|
->readOnly(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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('id')
|
||||||
|
// ->label('ID')
|
||||||
|
// ->numeric()
|
||||||
|
// ->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
|
->label('Plant')
|
||||||
|
->alignCenter()
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('name')
|
||||||
|
->label('Guard')
|
||||||
|
->alignCenter()
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->label('Created At')
|
||||||
|
->dateTime()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('created_by')
|
||||||
|
->label('Created By')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter(),
|
||||||
|
Tables\Columns\TextColumn::make('updated_at')
|
||||||
|
->label('Updated At')
|
||||||
|
->dateTime()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('deleted_at')
|
||||||
|
->label('Deleted At')
|
||||||
|
->dateTime()
|
||||||
|
->alignCenter()
|
||||||
|
->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()
|
||||||
|
->importer(GuardNameImporter::class)
|
||||||
|
->visible(function() {
|
||||||
|
return Filament::auth()->user()->can('view import guard name');
|
||||||
|
}),
|
||||||
|
ExportAction::make()
|
||||||
|
->exporter(GuardNameExporter::class)
|
||||||
|
->visible(function() {
|
||||||
|
return Filament::auth()->user()->can('view export guard name');
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListGuardNames::route('/'),
|
||||||
|
'create' => Pages\CreateGuardName::route('/create'),
|
||||||
|
'view' => Pages\ViewGuardName::route('/{record}'),
|
||||||
|
'edit' => Pages\EditGuardName::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()
|
||||||
|
->withoutGlobalScopes([
|
||||||
|
SoftDeletingScope::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\GuardNameResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\GuardNameResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateGuardName extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = GuardNameResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\GuardNameResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\GuardNameResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditGuardName extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = GuardNameResource::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\GuardNameResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\GuardNameResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListGuardNames extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = GuardNameResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\GuardNameResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\GuardNameResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewGuardName extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = GuardNameResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user