-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
838acb8
commit c4a44b1
Showing
4 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\PointTypeResource\Pages; | ||
use App\Models\PointType; | ||
use Filament\Forms; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
|
||
class PointTypeResource extends Resource | ||
{ | ||
protected static ?string $model = PointType::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; | ||
|
||
public static function getNavigationGroup(): ?string | ||
{ | ||
return __('nav.settings'); | ||
} | ||
|
||
public static function getModelLabel(): string | ||
{ | ||
return __('point_type.singular'); | ||
} | ||
|
||
public static function getPluralLabel(): ?string | ||
{ | ||
return __('point_type.plural'); | ||
} | ||
|
||
public static function getNavigationSort(): ?int | ||
{ | ||
return 4; | ||
} | ||
|
||
public static function getNavigationBadge(): ?string | ||
{ | ||
return (string) PointType::count(); | ||
} | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->label(__('common.name')), | ||
Forms\Components\Select::make('service_type_id') | ||
->required() | ||
->relationship('serviceType', 'name') | ||
->label(__('add_point.type.service_type')), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name') | ||
->label(__('point_type.fields.name')) | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('serviceType.name') | ||
->label(__('point_type.fields.service_type_id')) | ||
->searchable(), | ||
|
||
Tables\Columns\TextColumn::make('points_count') | ||
->counts('points') | ||
->label(__('point_type.fields.points_count')), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListPointTypes::route('/'), | ||
]; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public static function isDiscovered(): bool | ||
{ | ||
return false; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/Filament/Resources/PointTypeResource/Pages/ListPointTypes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\PointTypeResource\Pages; | ||
|
||
use App\Filament\Resources\PointTypeResource; | ||
use App\Models\ServiceType; | ||
use Filament\Actions; | ||
use Filament\Resources\Components\Tab; | ||
use Filament\Resources\Pages\ListRecords; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class ListPointTypes extends ListRecords | ||
{ | ||
protected static string $resource = PointTypeResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
|
||
public function getTabs(): array | ||
{ | ||
return ServiceType::all() | ||
->mapWithKeys(fn (ServiceType $serviceType) => [ | ||
$serviceType->slug => Tab::make($serviceType->slug) | ||
->label($serviceType->name) | ||
->modifyQueryUsing(fn (Builder $query) => $query->where('service_type_id', $serviceType->id)), | ||
]) | ||
->all(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
return[ | ||
'singular' => 'Tip punct', | ||
'plural' => 'Tipuri punct', | ||
'fields' => [ | ||
'name' => 'Nume', | ||
'service_type_id' => 'Tip serviciu', | ||
'points_count' => 'Număr puncte', | ||
], | ||
|
||
]; |