Skip to content

Commit c603991

Browse files
add "created by" filter, column, and relation to Point resource (#160)
fix #156
1 parent 4313f05 commit c603991

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

app/Filament/Resources/PointResource.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public static function table(Table $table): Table
6868
->relationship('county', 'name')
6969
->multiple(),
7070

71+
SelectFilter::make('created_by')
72+
->label(__('map_points.fields.created_by'))
73+
->relationship('createdBy', 'full_name')
74+
->multiple(),
75+
7176
SelectFilter::make('materials')
7277
->label(__('map_points.fields.materials'))
7378
->relationship('materials', 'name')
@@ -85,7 +90,7 @@ public static function table(Table $table): Table
8590
->icon('heroicon-m-eye'),
8691
Tables\Actions\Action::make('view_point_on_map')
8792
->label(__('map_points.buttons.view_on_map'))
88-
->url(fn (Point $record) => route('front.map.redirect', $record) )
93+
->url(fn (Point $record) => route('front.map.redirect', $record))
8994
->openUrlInNewTab()
9095
->icon('heroicon-m-map-pin'),
9196
])
@@ -259,6 +264,11 @@ public static function getColumns()
259264
->sortable()
260265
->wrap(),
261266

267+
TextColumn::make('createdBy.full_name')
268+
->label(__('map_points.fields.created_by'))
269+
->toggleable()
270+
->wrap(),
271+
262272
TextColumn::make('materials.name')
263273
->label(__('map_points.materials'))
264274
->searchable()
@@ -286,6 +296,7 @@ public static function getColumns()
286296

287297
TextColumn::make('proximity_count')
288298
->badge()
299+
->toggleable()
289300
->color(fn ($state) => $state > 0 ? 'warning' : 'success')
290301
->label(__('map_points.proximity_count')),
291302

app/Filament/Resources/PointResource/Pages/ViewMapPoint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ public function infolist(Infolist $infolist): Infolist
222222

223223
Section::make(__('map_points.sections.details'))
224224
->schema([
225+
226+
TextEntry::make('createdBy.full_name')
227+
->default('Admin HR')
228+
->label(__('map_points.fields.created_by')),
229+
225230
TextEntry::make('pointType.name')
226231
->label(__('map_points.fields.point_type')),
227232

app/Models/Point.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Database\Eloquent\Model;
1414
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1515
use Illuminate\Database\Eloquent\Relations\HasMany;
16+
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
1617
use Illuminate\Database\Eloquent\Relations\MorphOne;
1718
use Illuminate\Database\Eloquent\Relations\MorphToMany;
1819
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -120,6 +121,18 @@ public function user(): BelongsTo
120121
return $this->belongsTo(User::class, 'created_by');
121122
}
122123

124+
public function createdBy(): HasOneThrough
125+
{
126+
return $this->hasOneThrough(
127+
User::class,
128+
Contribution::class,
129+
'model_id',
130+
'id',
131+
'id',
132+
'user_id'
133+
)->where((new Contribution())->getTable() . '.model_type', (new static)->getMorphClass());
134+
}
135+
123136
public function contribution(): MorphOne
124137
{
125138
return $this->morphOne(Contribution::class, 'model');
@@ -155,6 +168,7 @@ public function url(): Attribute
155168
])
156169
);
157170
}
171+
158172
public function changeGroup(int $groupId): void
159173
{
160174
$this->update(['point_group_id' => $groupId]);
@@ -180,6 +194,7 @@ protected function makeAllSearchableUsing(Builder $query): Builder
180194
public function toSearchableArray(): array
181195
{
182196
$this->loadMissing(['serviceType:id,name', 'pointType:id,name', 'materials:id,name']);
197+
183198
return [
184199
'id' => (string) $this->id,
185200
'point_id' => (string) $this->id,

lang/ro/map_points.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
'latitude' => 'Latitudine',
7373
'longitude' => 'Longitudine',
7474
'point_type' => 'Tip punct',
75+
'created_by' => 'Creat de',
7576
'materials' => 'Materiale',
7677
'website' => 'Website',
7778
'phone' => 'Telefon',

0 commit comments

Comments
 (0)