Skip to content

Commit

Permalink
add point type resource
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Sep 30, 2024
1 parent 838acb8 commit c4a44b1
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
105 changes: 105 additions & 0 deletions app/Filament/Resources/PointTypeResource.php
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 app/Filament/Resources/PointTypeResource/Pages/ListPointTypes.php
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();
}
}
12 changes: 12 additions & 0 deletions app/Models/PointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class PointType extends Model
{
Expand All @@ -15,4 +17,14 @@ class PointType extends Model
'name',
'service_type_id',
];

public function serviceType(): BelongsTo
{
return $this->belongsTo(ServiceType::class);
}

public function points(): HasMany
{
return $this->hasMany(Point::class);
}
}
14 changes: 14 additions & 0 deletions lang/ro/point_type.php
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',
],

];

0 comments on commit c4a44b1

Please sign in to comment.