Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 23, 2023
1 parent ee8ed30 commit db298b3
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 2 deletions.
23 changes: 23 additions & 0 deletions app/Enums/BadgeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Enums;

use App\Concerns\Enums\Arrayable;
use App\Concerns\Enums\Comparable;
use App\Concerns\Enums\HasLabel;

enum BadgeType: string
{
use Arrayable;
use Comparable;
use HasLabel;

case AUTOMATED = 'automated';
case MANUAL = 'manual';
public function labelKeyPrefix(): string
{
return 'badge.types';
}
}
2 changes: 1 addition & 1 deletion app/Filament/Resources/BadgeCategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function table(Table $table): Table
])
->filters([
TernaryFilter::make('has_badges')
->label(__('badges.filters.has_badges'))
->label(__('badge.filters.has_badges'))
->queries(
true: fn (Builder $query) => $query->whereHas('badges'),
false: fn (Builder $query) => $query->whereDoesntHave('badges')
Expand Down
14 changes: 14 additions & 0 deletions app/Filament/Resources/BadgeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Resources;

use App\Enums\BadgeType;
use App\Filament\Resources\BadgeResource\Pages;
use App\Filament\Resources\BadgeResource\RelationManagers\UsersRelationManager;
use App\Models\Badge;
Expand Down Expand Up @@ -67,6 +68,15 @@ public static function form(Form $form): Form
->relationship('badgeCategory', 'title')
->required(),

Select::make('type')
->label(__('badge.type'))
->inlineLabel()
->columnSpanFull()
->options(BadgeType::options())
->default(BadgeType::MANUAL)
->disabled()
->required(),

Textarea::make('description')
->label(__('badge.description'))
->inlineLabel()
Expand Down Expand Up @@ -95,6 +105,10 @@ public static function table(Table $table): Table
->label(__('badge.title'))
->searchable()
->sortable(),
TextColumn::make('type')
->formatStateUsing(fn (Badge $record) => $record->type->label())
->label(__('badge.type'))
->sortable(),

TextColumn::make('users_count')
->label(__('badge.users_count'))
Expand Down
8 changes: 8 additions & 0 deletions app/Models/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Enums\BadgeType;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -22,6 +23,11 @@ class Badge extends Model implements HasMedia
protected $fillable = [
'title',
'description',
'type'
];

protected $casts =[
'type' => BadgeType::class
];

protected $appends = [
Expand Down Expand Up @@ -51,8 +57,10 @@ public function getImageAttribute(): string
{
return $this->getFirstMediaUrl(conversionName: 'thumb');
}

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

}
2 changes: 1 addition & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function organizationAdmin(): static
public function ngoManager(): static
{
return $this->state(fn (array $attributes) => [
// 'role' => UserRole::ngo_manager,
'role' => UserRole::MANAGER,
]);
}

Expand Down
2 changes: 2 additions & 0 deletions database/migrations/2023_07_04_005236_create_badges_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use App\Enums\BadgeType;
use App\Models\Badge;
use App\Models\BadgeCategory;
use App\Models\User;
Expand All @@ -21,6 +22,7 @@ public function up(): void
$table->timestamps();
$table->foreignIdFor(BadgeCategory::class)->constrained()->cascadeOnDelete();
$table->string('title');
$table->string('type')->default(BadgeType::MANUAL->value);
$table->text('description')->nullable();
});

Expand Down
5 changes: 5 additions & 0 deletions lang/ro/badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'description' => 'Descriere badge',
'image' => 'Imagine badge',
'users_count' => 'Număr de utilizatori cu accest badge',
'type' => 'Tip de badge',

'donor_count' => ':count donatori cu accest badge',

Expand All @@ -34,4 +35,8 @@
'singular' => 'Badge',
'plural' => 'Badge-uri',
],
'types' => [
'automated' => 'Automat',
'manual' => 'Manual',
],
];

0 comments on commit db298b3

Please sign in to comment.