-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add badge category in admin / wip on badges
- Loading branch information
1 parent
aefb674
commit ee8ed30
Showing
12 changed files
with
311 additions
and
6 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,95 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Enums\VolunteerStatus; | ||
use App\Filament\Resources\BadgeCategoryResource\Pages; | ||
use App\Filament\Resources\BadgeCategoryResource\RelationManagers; | ||
use App\Models\BadgeCategory; | ||
use App\Models\VolunteerRequest; | ||
use Filament\Forms; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Resources\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Resources\Table; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Filters\TernaryFilter; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\SoftDeletingScope; | ||
|
||
class BadgeCategoryResource extends Resource | ||
{ | ||
protected static ?string $model = BadgeCategory::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-collection'; | ||
|
||
protected static ?int $navigationSort = 6; | ||
|
||
public static function getPluralLabel(): ?string | ||
{ | ||
return __('badge.category.labels.plural'); | ||
} | ||
|
||
public static function getModelLabel(): string | ||
{ | ||
return __('badge.category.labels.singular'); | ||
} | ||
|
||
protected static function getNavigationGroup(): ?string | ||
{ | ||
return __('navigation.group.manage'); | ||
} | ||
|
||
protected static function getNavigationBadge(): ?string | ||
{ | ||
return (string) BadgeCategory::query()->whereHas('badges')->count(); | ||
} | ||
|
||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
TextInput::make('title') | ||
->label(__('badge.category.title')) | ||
->required() | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('title') | ||
->label(__('badge.category.title')) | ||
->searchable() | ||
->sortable(), | ||
TextColumn::make('badges_count') | ||
->counts('badges') | ||
->label(__('badge.category.badges_count')) | ||
->sortable(), | ||
]) | ||
->filters([ | ||
TernaryFilter::make('has_badges') | ||
->label(__('badges.filters.has_badges')) | ||
->queries( | ||
true: fn (Builder $query) => $query->whereHas('badges'), | ||
false: fn (Builder $query) => $query->whereDoesntHave('badges') | ||
), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListBadgeCategories::route('/'), | ||
]; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/Filament/Resources/BadgeCategoryResource/Pages/CreateBadgeCategory.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,12 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\BadgeCategoryResource\Pages; | ||
|
||
use App\Filament\Resources\BadgeCategoryResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateBadgeCategory extends CreateRecord | ||
{ | ||
protected static string $resource = BadgeCategoryResource::class; | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/BadgeCategoryResource/Pages/EditBadgeCategory.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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\BadgeCategoryResource\Pages; | ||
|
||
use App\Filament\Resources\BadgeCategoryResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditBadgeCategory extends EditRecord | ||
{ | ||
protected static string $resource = BadgeCategoryResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\DeleteAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/BadgeCategoryResource/Pages/ListBadgeCategories.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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\BadgeCategoryResource\Pages; | ||
|
||
use App\Filament\Resources\BadgeCategoryResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListBadgeCategories extends ListRecords | ||
{ | ||
protected static string $resource = BadgeCategoryResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
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
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class BadgeCategory extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'title', | ||
]; | ||
|
||
public function badges(): HasMany | ||
{ | ||
return $this->hasMany(Badge::class); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\BadgeCategory> | ||
*/ | ||
class BadgeCategoryFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'title' => $this->faker->title , | ||
]; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
database/migrations/2023_07_03_083038_create_badge_categories_table.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,28 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('badge_categories', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('title'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('badge_categories'); | ||
} | ||
}; |
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
Oops, something went wrong.