Skip to content

Commit

Permalink
Show times used for tags and items in admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
GeniJaho committed Mar 15, 2024
1 parent 6044b1a commit f936360
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 36 deletions.
9 changes: 8 additions & 1 deletion app/Filament/Resources/ItemResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ public static function table(Table $table): Table
TextColumn::make('name')
->sortable()
->searchable(),
TextColumn::make('photo_items_count')
->counts('photoItems')
->label('Times used')
->sortable()
->toggleable()
->numeric(),
TextColumn::make('slug')
->sortable()
->searchable(),
->searchable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('created_at')
->dateTime()
->sortable()
Expand Down
9 changes: 8 additions & 1 deletion app/Filament/Resources/TagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,17 @@ public static function table(Table $table): Table
->searchable(),
TextColumn::make('slug')
->sortable()
->searchable(),
->searchable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('type.name')
->sortable()
->searchable(),
TextColumn::make('photo_item_tags_count')
->counts('photoItemTags')
->label('Times used')
->sortable()
->toggleable()
->numeric(),
TextColumn::make('created_at')
->dateTime()
->sortable()
Expand Down
10 changes: 10 additions & 0 deletions app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @property PhotoItem|null $pivot
* @property Collection<Photo> $photos
* @property Collection<PhotoItem> $photoItems
*/
class Item extends Model
{
Expand All @@ -25,4 +27,12 @@ public function photos(): BelongsToMany
->using(PhotoItem::class)
->withTimestamps();
}

/**
* @return HasMany<PhotoItem>
*/
public function photoItems(): HasMany
{
return $this->hasMany(PhotoItem::class);
}
}
20 changes: 10 additions & 10 deletions app/Models/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class Photo extends Model
{
use HasFactory;

/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'user_id' => 'integer',
];
}

/**
* @return BelongsTo<User, Photo>
*/
Expand Down Expand Up @@ -95,14 +105,4 @@ public function scopeFilter(Builder $query, ?PhotoFilters $filters): void
->when($filters->is_tagged === true, fn ($query) => $query->whereHas('items'))
->when($filters->is_tagged === false, fn ($query) => $query->whereDoesntHave('items'));
}

/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'user_id' => 'integer',
];
}
}
24 changes: 12 additions & 12 deletions app/Models/PhotoItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ class PhotoItem extends Pivot

public $incrementing = true;

/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'picked_up' => 'boolean',
'recycled' => 'boolean',
'deposit' => 'boolean',
];
}

/**
* @return BelongsTo<Item, PhotoItem>
*/
Expand Down Expand Up @@ -53,16 +65,4 @@ public function tags(): BelongsToMany
->using(PhotoItemTag::class)
->withTimestamps();
}

/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'picked_up' => 'boolean',
'recycled' => 'boolean',
'deposit' => 'boolean',
];
}
}
11 changes: 10 additions & 1 deletion app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Tag extends Model
{
Expand All @@ -13,10 +14,18 @@ class Tag extends Model
protected $guarded = [];

/**
* @return BelongsTo<TagType, \App\Models\Tag>
* @return BelongsTo<TagType, Tag>
*/
public function type(): BelongsTo
{
return $this->belongsTo(TagType::class, 'tag_type_id');
}

/**
* @return HasMany<PhotoItemTag>
*/
public function photoItemTags(): HasMany
{
return $this->hasMany(PhotoItemTag::class);
}
}
22 changes: 11 additions & 11 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
'profile_photo_url',
];

/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'settings' => UserSettings::class.':default',
];
}

public function canAccessPanel(Panel $panel): bool
{
return in_array($this->email, [
Expand Down Expand Up @@ -119,15 +130,4 @@ public function photos(): HasMany
{
return $this->hasMany(Photo::class);
}

/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'settings' => UserSettings::class.':default',
];
}
}

0 comments on commit f936360

Please sign in to comment.