feat: add ApiResponse trait for standardized API responses
chore: update composer dependencies to include phppresentation chore: update composer.lock after adding phppresentation feat: create categories migration for category management feat: create templates migration for template storage feat: create template generations migration for tracking template usage feat: create template keys migration for template customization feat: create notifications migration for user notifications feat: update API routes for categories, templates, and user profile management docs: update API documentation to include new endpoints for profile and wallet
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notifications;
|
||||
|
||||
use App\Filament\Resources\Notifications\Pages\CreateNotification;
|
||||
use App\Filament\Resources\Notifications\Pages\EditNotification;
|
||||
use App\Filament\Resources\Notifications\Pages\ListNotifications;
|
||||
use App\Filament\Resources\Notifications\Pages\ViewNotification;
|
||||
use App\Filament\Resources\Notifications\Schemas\NotificationForm;
|
||||
use App\Filament\Resources\Notifications\Tables\NotificationsTable;
|
||||
use App\Models\Notification;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class NotificationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Notification::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBell;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'اعلانها';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'title';
|
||||
|
||||
protected static ?string $modelLabel = 'نوتیفیکیشن';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'نوتیفیکیشنها';
|
||||
|
||||
protected static ?string $navigationLabel = 'نوتیفیکیشنها';
|
||||
|
||||
protected static ?int $navigationSort = 30;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return NotificationForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return NotificationsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListNotifications::route('/'),
|
||||
'create' => CreateNotification::route('/create'),
|
||||
'view' => ViewNotification::route('/{record}'),
|
||||
'edit' => EditNotification::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notifications\Pages;
|
||||
|
||||
use App\Filament\Resources\Notifications\NotificationResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateNotification extends CreateRecord
|
||||
{
|
||||
protected static string $resource = NotificationResource::class;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notifications\Pages;
|
||||
|
||||
use App\Filament\Resources\Notifications\NotificationResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditNotification extends EditRecord
|
||||
{
|
||||
protected static string $resource = NotificationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ViewAction::make(),
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notifications\Pages;
|
||||
|
||||
use App\Filament\Resources\Notifications\NotificationResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListNotifications extends ListRecords
|
||||
{
|
||||
protected static string $resource = NotificationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notifications\Pages;
|
||||
|
||||
use App\Filament\Resources\Notifications\NotificationResource;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewNotification extends ViewRecord
|
||||
{
|
||||
protected static string $resource = NotificationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notifications\Schemas;
|
||||
|
||||
use App\Enums\NotificationType;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class NotificationForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('user_id')
|
||||
->label('کاربر')
|
||||
->relationship('user', 'name')
|
||||
->searchable()
|
||||
->required(),
|
||||
Select::make('type')
|
||||
->label('نوع')
|
||||
->options(collect(NotificationType::cases())->mapWithKeys(fn (NotificationType $type) => [$type->value => $type->label()]))
|
||||
->required(),
|
||||
TextInput::make('title')
|
||||
->label('عنوان')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Textarea::make('body')
|
||||
->label('متن')
|
||||
->required()
|
||||
->rows(4),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notifications\Tables;
|
||||
|
||||
use App\Enums\NotificationType;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class NotificationsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('user.name')
|
||||
->label('کاربر')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('type')
|
||||
->label('نوع')
|
||||
->badge()
|
||||
->formatStateUsing(fn (NotificationType $state): string => $state->label()),
|
||||
TextColumn::make('title')
|
||||
->label('عنوان')
|
||||
->searchable()
|
||||
->limit(40),
|
||||
IconColumn::make('read_at')
|
||||
->label('خوانده شده')
|
||||
->boolean()
|
||||
->getStateUsing(fn ($record): bool => $record->read_at !== null),
|
||||
TextColumn::make('created_at')
|
||||
->label('تاریخ ایجاد')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
SelectFilter::make('type')
|
||||
->label('نوع')
|
||||
->options(collect(NotificationType::cases())->mapWithKeys(fn (NotificationType $type) => [$type->value => $type->label()])),
|
||||
TernaryFilter::make('read_at')
|
||||
->label('وضعیت')
|
||||
->placeholder('همه')
|
||||
->trueLabel('خوانده شده')
|
||||
->falseLabel('خوانده نشده')
|
||||
->queries(
|
||||
true: fn ($query) => $query->whereNotNull('read_at'),
|
||||
false: fn ($query) => $query->whereNull('read_at'),
|
||||
),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user