chore: code refactor via rector
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use App\Models\ActivationKey;
|
||||
use App\Models\Plan;
|
||||
use Filament\Actions\BulkAction;
|
||||
@@ -19,17 +23,16 @@ use Filament\Tables\Filters\SelectFilter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Response;
|
||||
use Str;
|
||||
|
||||
class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
{
|
||||
use InteractsWithForms, InteractsWithTable;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-key';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-key';
|
||||
|
||||
protected string $view = 'filament.pages.generate-activation-keys';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Admin';
|
||||
|
||||
protected static ?string $title = 'Activation Keys';
|
||||
|
||||
@@ -59,13 +62,13 @@ class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
];
|
||||
}
|
||||
|
||||
public function generate()
|
||||
public function generate(): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$plan = Plan::findOrFail($data['plan_id']);
|
||||
$plan = Plan::query()->findOrFail($data['plan_id']);
|
||||
|
||||
for ($i = 0; $i < $data['quantity']; $i++) {
|
||||
ActivationKey::create([
|
||||
ActivationKey::query()->create([
|
||||
'price_id' => $plan->pricing_id,
|
||||
'activation_key' => strtoupper('Z'.Str::random(16)),
|
||||
'is_activated' => false,
|
||||
@@ -99,8 +102,8 @@ class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
|
||||
TextColumn::make('billing_interval')
|
||||
->label('Interval')
|
||||
->getStateUsing(function ($record) {
|
||||
$isMonthly = Plan::where('pricing_id', $record->price_id)->value('monthly_billing');
|
||||
->getStateUsing(function ($record): string {
|
||||
$isMonthly = Plan::query()->where('pricing_id', $record->price_id)->value('monthly_billing');
|
||||
|
||||
return $isMonthly ? 'Monthly' : 'Yearly';
|
||||
}),
|
||||
@@ -121,7 +124,7 @@ class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
SelectFilter::make('price_id')
|
||||
->label('Plan')
|
||||
->options(
|
||||
Plan::pluck('name', 'pricing_id')
|
||||
Plan::query()->pluck('name', 'pricing_id')
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -130,13 +133,13 @@ class GenerateActivationKeys extends Page implements HasForms, HasTable
|
||||
{
|
||||
return [
|
||||
BulkAction::make('Download Keys')
|
||||
->action(fn (Collection $records) => $this->downloadKeys($records))
|
||||
->action(fn (Collection $records): BinaryFileResponse => $this->downloadKeys($records))
|
||||
->deselectRecordsAfterCompletion()
|
||||
->requiresConfirmation(),
|
||||
];
|
||||
}
|
||||
|
||||
public function downloadKeys(Collection $records)
|
||||
public function downloadKeys(Collection $records): BinaryFileResponse
|
||||
{
|
||||
$text = $records->pluck('activation_key')->implode("\n");
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Models\Setting;
|
||||
use App\Models\ZEmail;
|
||||
use Artisan;
|
||||
use Exception;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\KeyValue;
|
||||
@@ -25,17 +27,17 @@ class Settings extends Page implements HasForms
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-cog-6-tooth';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cog-6-tooth';
|
||||
|
||||
protected string $view = 'filament.pages.settings';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Web Master';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Web Master';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
$auth_email = $user->email;
|
||||
$setting = Setting::where('app_admin', $auth_email)->first();
|
||||
$setting = Setting::query()->where('app_admin', $auth_email)->first();
|
||||
|
||||
if ($setting) {
|
||||
$imapSettings = $setting->imap_settings ?? [];
|
||||
@@ -50,7 +52,7 @@ class Settings extends Page implements HasForms
|
||||
]);
|
||||
|
||||
$this->applyDefaults($configurationSettings, [
|
||||
'cron_password' => fn () => $this->generateRandomString(20),
|
||||
'cron_password' => fn (): string => $this->generateRandomString(20),
|
||||
'date_format' => 'd M Y h:i A',
|
||||
'after_last_email_delete' => 'redirect_to_homepage',
|
||||
]);
|
||||
@@ -68,9 +70,7 @@ class Settings extends Page implements HasForms
|
||||
|
||||
foreach ($transformMap as $key => $subKey) {
|
||||
if (isset($configurationSettings[$key])) {
|
||||
$configurationSettings[$key] = array_map(function ($value) use ($subKey) {
|
||||
return [$subKey => $value];
|
||||
}, $configurationSettings[$key]);
|
||||
$configurationSettings[$key] = array_map(fn($value): array => [$subKey => $value], $configurationSettings[$key]);
|
||||
}
|
||||
}
|
||||
$this->form->fill([
|
||||
@@ -376,12 +376,11 @@ class Settings extends Page implements HasForms
|
||||
$data = $this->form->getState();
|
||||
if (! $this->testIMAP($data['imap_settings'])) {
|
||||
return;
|
||||
} else {
|
||||
Notification::make()
|
||||
->title('IMAP Connection Successful')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
Notification::make()
|
||||
->title('IMAP Connection Successful')
|
||||
->success()
|
||||
->send();
|
||||
foreach ([
|
||||
'protocol' => 'imap',
|
||||
'default_account' => 'default',
|
||||
@@ -410,7 +409,7 @@ class Settings extends Page implements HasForms
|
||||
}
|
||||
}
|
||||
|
||||
$setting = Setting::where('id', 1)->first();
|
||||
$setting = Setting::query()->where('id', 1)->first();
|
||||
|
||||
$user = auth()->user();
|
||||
$auth_email = $user->email;
|
||||
@@ -447,7 +446,7 @@ class Settings extends Page implements HasForms
|
||||
'configuration_settings' => $data['configuration_settings'],
|
||||
'ads_settings' => $data['ads_settings'],
|
||||
];
|
||||
$create_res = Setting::create(array_merge($data));
|
||||
$create_res = Setting::query()->create(array_merge($data));
|
||||
|
||||
if ($create_res) {
|
||||
Notification::make()
|
||||
@@ -464,13 +463,13 @@ class Settings extends Page implements HasForms
|
||||
}
|
||||
}
|
||||
|
||||
private function generateRandomString($length = 10): string
|
||||
private function generateRandomString(int $length = 10): string
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use App\Filament\Resources\BlogResource\Pages\CreateBlog;
|
||||
use App\Filament\Resources\BlogResource\Pages\EditBlog;
|
||||
use App\Filament\Resources\BlogResource\Pages\ListBlogs;
|
||||
@@ -33,13 +35,13 @@ class BlogResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Blog::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-m-newspaper';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-m-newspaper';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Content';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Content';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
$categories = Category::pluck('name', 'id')->toArray();
|
||||
Category::query()->pluck('name', 'id')->toArray();
|
||||
|
||||
return $schema
|
||||
->components([
|
||||
@@ -50,7 +52,7 @@ class BlogResource extends Resource
|
||||
->required()
|
||||
->live(1)
|
||||
->columnSpanFull()
|
||||
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
|
||||
->afterStateUpdated(fn (Set $set, ?string $state): mixed => $set('slug', Str::slug($state))),
|
||||
|
||||
TextInput::make('slug')
|
||||
->required()
|
||||
@@ -132,7 +134,7 @@ class BlogResource extends Resource
|
||||
Action::make('togglePublished')
|
||||
->label('Toggle Published')
|
||||
->icon('heroicon-o-eye')
|
||||
->action(function (Blog $record) {
|
||||
->action(function (Blog $record): void {
|
||||
$record->update(['is_published' => ! $record->is_published]);
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use App\Filament\Resources\CategoryResource\Pages\CreateCategory;
|
||||
use App\Filament\Resources\CategoryResource\Pages\EditCategory;
|
||||
use App\Filament\Resources\CategoryResource\Pages\ListCategories;
|
||||
@@ -26,9 +28,9 @@ class CategoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Category::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-ticket';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-ticket';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Content';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Content';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
@@ -37,7 +39,7 @@ class CategoryResource extends Resource
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->live(1)
|
||||
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
|
||||
->afterStateUpdated(fn (Set $set, ?string $state): mixed => $set('slug', Str::slug($state))),
|
||||
TextInput::make('slug')->required(),
|
||||
Select::make('is_active')
|
||||
->options([
|
||||
@@ -58,9 +60,7 @@ class CategoryResource extends Resource
|
||||
TextColumn::make('slug'),
|
||||
TextColumn::make('blogs_count')
|
||||
->label('Blogs')
|
||||
->getStateUsing(function (Category $record): int {
|
||||
return $record->blogs()->count();
|
||||
}),
|
||||
->getStateUsing(fn(Category $record): int => $record->blogs()->count()),
|
||||
IconColumn::make('is_active')->label('Active')->boolean(),
|
||||
])
|
||||
->filters([
|
||||
@@ -73,7 +73,7 @@ class CategoryResource extends Resource
|
||||
Action::make('toggleStatus')
|
||||
->label('Toggle Status')
|
||||
->icon('heroicon-o-power')
|
||||
->action(function (Category $record) {
|
||||
->action(function (Category $record): void {
|
||||
$record->update(['is_active' => ! $record->is_active]);
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use App\Filament\Resources\MenuResource\Pages\CreateMenu;
|
||||
use App\Filament\Resources\MenuResource\Pages\EditMenu;
|
||||
use App\Filament\Resources\MenuResource\Pages\ListMenus;
|
||||
@@ -24,13 +26,13 @@ class MenuResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Menu::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-bars-3-bottom-left';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-bars-3-bottom-left';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Content';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Content';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
$menus = Menu::Pluck('name', 'id')->toArray();
|
||||
$menus = Menu::query()->Pluck('name', 'id')->toArray();
|
||||
|
||||
return $schema
|
||||
->components([
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use App\Filament\Resources\PageResource\Pages\CreatePage;
|
||||
use App\Filament\Resources\PageResource\Pages\EditPage;
|
||||
use App\Filament\Resources\PageResource\Pages\ListPages;
|
||||
@@ -32,13 +34,13 @@ class PageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Page::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-document';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-document';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Content';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Content';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
$pages = Page::Pluck('title', 'id')->toArray();
|
||||
$pages = Page::query()->Pluck('title', 'id')->toArray();
|
||||
|
||||
return $schema
|
||||
->components([
|
||||
@@ -50,7 +52,7 @@ class PageResource extends Resource
|
||||
->required()
|
||||
->live(1)
|
||||
->columnSpanFull()
|
||||
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),
|
||||
->afterStateUpdated(fn (Set $set, ?string $state): mixed => $set('slug', Str::slug($state))),
|
||||
TextInput::make('slug')->required()->columnSpan(3),
|
||||
Select::make('is_published')
|
||||
->options([
|
||||
@@ -114,7 +116,7 @@ class PageResource extends Resource
|
||||
Action::make('togglePublished')
|
||||
->label('Toggle Published')
|
||||
->icon('heroicon-o-eye')
|
||||
->action(function (Page $record) {
|
||||
->action(function (Page $record): void {
|
||||
$record->update(['is_published' => ! $record->is_published]);
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use App\Filament\Resources\PlanResource\Pages\CreatePlan;
|
||||
use App\Filament\Resources\PlanResource\Pages\EditPlan;
|
||||
use App\Filament\Resources\PlanResource\Pages\ListPlans;
|
||||
@@ -26,9 +28,9 @@ class PlanResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Plan::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Web Master';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Web Master';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use App\Filament\Resources\TicketResource\Pages\CreateTicket;
|
||||
use App\Filament\Resources\TicketResource\Pages\EditTicket;
|
||||
use App\Filament\Resources\TicketResource\Pages\ListTickets;
|
||||
@@ -23,7 +25,6 @@ use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\BadgeColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
@@ -37,9 +38,9 @@ class TicketResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Ticket::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-ticket';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-ticket';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Support';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Support';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
@@ -91,9 +92,9 @@ class TicketResource extends Resource
|
||||
->searchable(),
|
||||
BadgeColumn::make('status')
|
||||
->colors([
|
||||
'success' => fn ($state) => $state === 'open',
|
||||
'warning' => fn ($state) => $state === 'pending',
|
||||
'danger' => fn ($state) => $state === 'closed',
|
||||
'success' => fn ($state): bool => $state === 'open',
|
||||
'warning' => fn ($state): bool => $state === 'pending',
|
||||
'danger' => fn ($state): bool => $state === 'closed',
|
||||
])
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
@@ -119,11 +120,9 @@ class TicketResource extends Resource
|
||||
DatePicker::make('created_from')->label('Created From'),
|
||||
DatePicker::make('created_until')->label('Created Until'),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
return $query
|
||||
->when($data['created_from'], fn ($query, $date) => $query->whereDate('created_at', '>=', $date))
|
||||
->when($data['created_until'], fn ($query, $date) => $query->whereDate('created_at', '<=', $date));
|
||||
}),
|
||||
->query(fn($query, array $data) => $query
|
||||
->when($data['created_from'], fn ($query, $date) => $query->whereDate('created_at', '>=', $date))
|
||||
->when($data['created_until'], fn ($query, $date) => $query->whereDate('created_at', '<=', $date))),
|
||||
])
|
||||
// ->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
@@ -135,26 +134,24 @@ class TicketResource extends Resource
|
||||
Action::make('view')
|
||||
->label('View & Respond')
|
||||
->icon('heroicon-o-eye')
|
||||
->schema(function (Ticket $ticket): array {
|
||||
return [
|
||||
TextArea::make('response')
|
||||
->label('Your Response')
|
||||
->required()
|
||||
->rows(7)
|
||||
->placeholder('Type your response here...'),
|
||||
->schema(fn(Ticket $ticket): array => [
|
||||
TextArea::make('response')
|
||||
->label('Your Response')
|
||||
->required()
|
||||
->rows(7)
|
||||
->placeholder('Type your response here...'),
|
||||
|
||||
Select::make('status')
|
||||
->label('Ticket Status')
|
||||
->options([
|
||||
'open' => 'Open',
|
||||
'pending' => 'In Progress',
|
||||
'closed' => 'Closed',
|
||||
])
|
||||
->default($ticket->status === 'open' ? 'pending' : $ticket->status)
|
||||
->required(),
|
||||
];
|
||||
})
|
||||
->modalContent(function (Ticket $ticket) {
|
||||
Select::make('status')
|
||||
->label('Ticket Status')
|
||||
->options([
|
||||
'open' => 'Open',
|
||||
'pending' => 'In Progress',
|
||||
'closed' => 'Closed',
|
||||
])
|
||||
->default($ticket->status === 'open' ? 'pending' : $ticket->status)
|
||||
->required(),
|
||||
])
|
||||
->modalContent(function (Ticket $ticket): HtmlString {
|
||||
$html = '<div class="space-y-3 mb-3 text-sm">';
|
||||
|
||||
// Ticket Subject & Message
|
||||
@@ -185,8 +182,8 @@ class TicketResource extends Resource
|
||||
return new HtmlString($html);
|
||||
})
|
||||
|
||||
->action(function (array $data, Ticket $ticket) {
|
||||
TicketResponse::create([
|
||||
->action(function (array $data, Ticket $ticket): void {
|
||||
TicketResponse::query()->create([
|
||||
'ticket_id' => $ticket->id,
|
||||
'user_id' => auth()->id(),
|
||||
'response' => $data['response'],
|
||||
@@ -214,7 +211,7 @@ class TicketResource extends Resource
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (Ticket $ticket): bool => $ticket->status !== 'closed')
|
||||
->action(function (Ticket $ticket) {
|
||||
->action(function (Ticket $ticket): void {
|
||||
$ticket->update(['status' => 'closed']);
|
||||
}),
|
||||
Action::make('reopen')
|
||||
@@ -222,7 +219,7 @@ class TicketResource extends Resource
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('success')
|
||||
->visible(fn (Ticket $ticket): bool => $ticket->status === 'closed')
|
||||
->action(function (Ticket $ticket) {
|
||||
->action(function (Ticket $ticket): void {
|
||||
$ticket->update(['status' => 'open']);
|
||||
}),
|
||||
])
|
||||
@@ -235,7 +232,7 @@ class TicketResource extends Resource
|
||||
->icon('heroicon-o-envelope')
|
||||
->requiresConfirmation()
|
||||
->deselectRecordsAfterCompletion()
|
||||
->action(function (Collection $records) {
|
||||
->action(function (Collection $records): void {
|
||||
foreach ($records as $ticket) {
|
||||
$responses = $ticket->responses()
|
||||
->with('user')
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use BackedEnum;
|
||||
use UnitEnum;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Filament\Resources\UserResource\Pages\CreateUser;
|
||||
use App\Filament\Resources\UserResource\Pages\EditUser;
|
||||
use App\Filament\Resources\UserResource\Pages\ListUsers;
|
||||
use App\Filament\Resources\UserResource\RelationManagers\LogsRelationManager;
|
||||
use App\Filament\Resources\UserResource\RelationManagers\UsageLogsRelationManager;
|
||||
use App\Models\User;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
@@ -31,9 +33,9 @@ class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-users';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-users';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Admin';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
@@ -50,7 +52,7 @@ class UserResource extends Resource
|
||||
TextInput::make('email_verified_at')
|
||||
->label('Email Verification Status')
|
||||
->disabled()
|
||||
->formatStateUsing(fn ($record) => $record->email_verified_at ?? ''
|
||||
->formatStateUsing(fn ($record): string => $record->email_verified_at ?? ''
|
||||
? 'Verified at '.$record->email_verified_at->toDateTimeString()
|
||||
: 'Not Verified')
|
||||
->helperText('Shows whether the user has verified their email address.'),
|
||||
@@ -96,22 +98,20 @@ class UserResource extends Resource
|
||||
->falseIcon('heroicon-o-x-circle')
|
||||
->trueColor('success')
|
||||
->falseColor('danger')
|
||||
->getStateUsing(fn ($record) => ! is_null($record->email_verified_at))
|
||||
->getStateUsing(fn ($record): bool => ! is_null($record->email_verified_at))
|
||||
->sortable(),
|
||||
BadgeColumn::make('level')
|
||||
->label('User Level')
|
||||
->getStateUsing(function ($record) {
|
||||
return match ($record->level) {
|
||||
0 => 'Normal User',
|
||||
1 => 'Banned',
|
||||
9 => 'Super Admin',
|
||||
default => 'Unknown', // In case some invalid level exists
|
||||
};
|
||||
->getStateUsing(fn($record): string => match ($record->level) {
|
||||
0 => 'Normal User',
|
||||
1 => 'Banned',
|
||||
9 => 'Super Admin',
|
||||
default => 'Unknown', // In case some invalid level exists
|
||||
})
|
||||
->colors([
|
||||
'success' => fn ($state) => $state === 'Normal User',
|
||||
'danger' => fn ($state) => $state === 'Banned',
|
||||
'warning' => fn ($state) => $state === 'Super Admin',
|
||||
'success' => fn ($state): bool => $state === 'Normal User',
|
||||
'danger' => fn ($state): bool => $state === 'Banned',
|
||||
'warning' => fn ($state): bool => $state === 'Super Admin',
|
||||
])
|
||||
->sortable(),
|
||||
TextColumn::make('stripe_id')->label('Stripe ID')->copyable(),
|
||||
@@ -126,14 +126,14 @@ class UserResource extends Resource
|
||||
'subscribed' => 'Has Active Subscription',
|
||||
'not_subscribed' => 'No Active Subscription',
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
->query(function ($query, array $data): void {
|
||||
if ($data['value'] === 'subscribed') {
|
||||
$query->whereHas('subscriptions', function ($query) {
|
||||
$query->whereHas('subscriptions', function ($query): void {
|
||||
$query->where('stripe_status', 'active')
|
||||
->orWhere('stripe_status', 'trialing');
|
||||
});
|
||||
} elseif ($data['value'] === 'not_subscribed') {
|
||||
$query->whereDoesntHave('subscriptions', function ($query) {
|
||||
$query->whereDoesntHave('subscriptions', function ($query): void {
|
||||
$query->where('stripe_status', 'active')
|
||||
->orWhere('stripe_status', 'trialing');
|
||||
});
|
||||
@@ -145,7 +145,7 @@ class UserResource extends Resource
|
||||
'verified' => 'Verified',
|
||||
'not_verified' => 'Not Verified',
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
->query(function ($query, array $data): void {
|
||||
if ($data['value'] === 'verified') {
|
||||
$query->whereNotNull('email_verified_at');
|
||||
} elseif ($data['value'] === 'not_verified') {
|
||||
@@ -161,12 +161,10 @@ class UserResource extends Resource
|
||||
DeleteBulkAction::make(),
|
||||
BulkAction::make('updateLevel')
|
||||
->label('Update User Level')
|
||||
->action(function (Collection $records, array $data) {
|
||||
->action(function (Collection $records, array $data): void {
|
||||
|
||||
$newLevel = $data['new_level'];
|
||||
if ($newLevel === 9) {
|
||||
throw new Exception('User level cannot be 9 or higher.');
|
||||
}
|
||||
throw_if($newLevel === 9, Exception::class, 'User level cannot be 9 or higher.');
|
||||
|
||||
DB::table('users')
|
||||
->whereIn('id', $records->pluck('id'))
|
||||
|
||||
@@ -75,7 +75,7 @@ class EditUser extends EditRecord
|
||||
fclose($csv);
|
||||
|
||||
return Response::streamDownload(
|
||||
function () use ($csvContent) {
|
||||
function () use ($csvContent): void {
|
||||
echo $csvContent;
|
||||
},
|
||||
"user_{$record->id}_report_".now()->format('Ymd_His').'.csv',
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Filament\Resources\UserResource\RelationManagers;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Filament\Resources\UserResource\RelationManagers;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Log;
|
||||
use App\Models\Meta;
|
||||
use App\Models\PremiumEmail;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
@@ -26,39 +26,39 @@ class StatsOverview extends BaseWidget
|
||||
->descriptionIcon($this->getComparisonIcon($this->getCustomerCount(), $this->getCustomerCount('yesterday')))
|
||||
->color($this->getComparisonColor($this->getCustomerCount(), $this->getCustomerCount('yesterday'))),
|
||||
Stat::make('Paid Users', $this->getUserPaid())
|
||||
->description($this->getComparisonDescription($this->getUserPaid(), $this->getUserPaid('yesterday')))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getUserPaid(), $this->getUserPaid('yesterday')))
|
||||
->color($this->getComparisonColor($this->getUserPaid(), $this->getUserPaid('yesterday'))),
|
||||
->description($this->getComparisonDescription($this->getUserPaid(), $this->getUserPaid()))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getUserPaid(), $this->getUserPaid()))
|
||||
->color($this->getComparisonColor($this->getUserPaid(), $this->getUserPaid())),
|
||||
Stat::make('Logs Count', $this->getLogsCount())
|
||||
->description($this->getComparisonDescription($this->getLogsCount(), $this->getLogsCount('yesterday')))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getLogsCount(), $this->getLogsCount('yesterday')))
|
||||
->color($this->getComparisonColor($this->getLogsCount(), $this->getLogsCount('yesterday'))),
|
||||
Stat::make('Total Mailbox', $this->getTotalMailbox())
|
||||
->description($this->getComparisonDescription($this->getTotalMailbox(), $this->getTotalMailbox('yesterday')))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getTotalMailbox(), $this->getTotalMailbox('yesterday')))
|
||||
->color($this->getComparisonColor($this->getTotalMailbox(), $this->getTotalMailbox('yesterday'))),
|
||||
->description($this->getComparisonDescription($this->getTotalMailbox(), $this->getTotalMailbox()))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getTotalMailbox(), $this->getTotalMailbox()))
|
||||
->color($this->getComparisonColor($this->getTotalMailbox(), $this->getTotalMailbox())),
|
||||
Stat::make('Emails Received', $this->getTotalEmailsReceived())
|
||||
->description($this->getComparisonDescription($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived('yesterday')))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived('yesterday')))
|
||||
->color($this->getComparisonColor($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived('yesterday'))),
|
||||
->description($this->getComparisonDescription($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived()))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived()))
|
||||
->color($this->getComparisonColor($this->getTotalEmailsReceived(), $this->getTotalEmailsReceived())),
|
||||
Stat::make('Emails Stored', $this->getStoreEmailsCount())
|
||||
->description($this->getComparisonDescription($this->getStoreEmailsCount(), $this->getStoreEmailsCount('yesterday')))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getStoreEmailsCount(), $this->getStoreEmailsCount('yesterday')))
|
||||
->color($this->getComparisonColor($this->getStoreEmailsCount(), $this->getStoreEmailsCount('yesterday'))),
|
||||
Stat::make('Open Tickets', $this->getOpenTicketsCount())
|
||||
->description($this->getComparisonDescription($this->getOpenTicketsCount(), $this->getOpenTicketsCount('yesterday')))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getOpenTicketsCount(), $this->getOpenTicketsCount('yesterday')))
|
||||
->color($this->getComparisonColor($this->getOpenTicketsCount(), $this->getOpenTicketsCount('yesterday'))),
|
||||
->description($this->getComparisonDescription($this->getOpenTicketsCount(), $this->getOpenTicketsCount()))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getOpenTicketsCount(), $this->getOpenTicketsCount()))
|
||||
->color($this->getComparisonColor($this->getOpenTicketsCount(), $this->getOpenTicketsCount())),
|
||||
Stat::make('Closed Tickets', $this->getClosedTicketsCount())
|
||||
->description($this->getComparisonDescription($this->getClosedTicketsCount(), $this->getClosedTicketsCount('yesterday')))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getClosedTicketsCount(), $this->getClosedTicketsCount('yesterday')))
|
||||
->color($this->getComparisonColor($this->getClosedTicketsCount(), $this->getClosedTicketsCount('yesterday'))),
|
||||
->description($this->getComparisonDescription($this->getClosedTicketsCount(), $this->getClosedTicketsCount()))
|
||||
->descriptionIcon($this->getComparisonIcon($this->getClosedTicketsCount(), $this->getClosedTicketsCount()))
|
||||
->color($this->getComparisonColor($this->getClosedTicketsCount(), $this->getClosedTicketsCount())),
|
||||
];
|
||||
}
|
||||
|
||||
private function getComparisonDescription(int $today, int $yesterday): string
|
||||
{
|
||||
if ($today == $yesterday) {
|
||||
if ($today === $yesterday) {
|
||||
return 'No change';
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class StatsOverview extends BaseWidget
|
||||
|
||||
private function getComparisonIcon(int $today, int $yesterday): ?string
|
||||
{
|
||||
if ($today == $yesterday) {
|
||||
if ($today === $yesterday) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class StatsOverview extends BaseWidget
|
||||
|
||||
private function getComparisonColor(int $today, int $yesterday): string
|
||||
{
|
||||
if ($today == $yesterday) {
|
||||
if ($today === $yesterday) {
|
||||
return 'gray';
|
||||
}
|
||||
|
||||
@@ -95,13 +95,13 @@ class StatsOverview extends BaseWidget
|
||||
private function getUser(string $period = 'today'): int
|
||||
{
|
||||
if ($period === 'yesterday') {
|
||||
return User::where('created_at', '<', Carbon::today('UTC')->startOfDay())->count();
|
||||
return User::query()->where('created_at', '<', Date::today('UTC')->startOfDay())->count();
|
||||
}
|
||||
|
||||
return User::count();
|
||||
return User::query()->count();
|
||||
}
|
||||
|
||||
private function getUserPaid(string $period = 'today'): int
|
||||
private function getUserPaid(): int
|
||||
{
|
||||
return DB::table('subscriptions')
|
||||
->where('stripe_status', 'active')
|
||||
@@ -112,49 +112,49 @@ class StatsOverview extends BaseWidget
|
||||
private function getLogsCount(string $period = 'today'): int
|
||||
{
|
||||
if ($period === 'yesterday') {
|
||||
return Log::where('created_at', '<', Carbon::today('UTC')->startOfDay())->count();
|
||||
return Log::query()->where('created_at', '<', Date::today('UTC')->startOfDay())->count();
|
||||
}
|
||||
|
||||
return Log::count();
|
||||
return Log::query()->count();
|
||||
}
|
||||
|
||||
private function getTotalMailbox(string $period = 'today'): int
|
||||
private function getTotalMailbox(): int
|
||||
{
|
||||
return Meta::select('value')->where('key', 'email_ids_created')->first()->value ?? 0;
|
||||
return Meta::query()->select('value')->where('key', 'email_ids_created')->first()->value ?? 0;
|
||||
}
|
||||
|
||||
private function getTotalEmailsReceived(string $period = 'today'): int
|
||||
private function getTotalEmailsReceived(): int
|
||||
{
|
||||
return Meta::select('value')->where('key', 'messages_received')->first()->value ?? 0;
|
||||
return Meta::query()->select('value')->where('key', 'messages_received')->first()->value ?? 0;
|
||||
}
|
||||
|
||||
private function getCustomerCount(string $period = 'today'): int
|
||||
{
|
||||
if ($period === 'yesterday') {
|
||||
return User::whereNotNull('stripe_id')
|
||||
->where('created_at', '<', Carbon::today('UTC')->startOfDay())
|
||||
return User::query()->whereNotNull('stripe_id')
|
||||
->where('created_at', '<', Date::today('UTC')->startOfDay())
|
||||
->count();
|
||||
}
|
||||
|
||||
return User::whereNotNull('stripe_id')->count();
|
||||
return User::query()->whereNotNull('stripe_id')->count();
|
||||
}
|
||||
|
||||
private function getStoreEmailsCount(string $period = 'today'): int
|
||||
{
|
||||
if ($period === 'yesterday') {
|
||||
return PremiumEmail::where('created_at', '<', Carbon::today('UTC')->startOfDay())->count();
|
||||
return PremiumEmail::query()->where('created_at', '<', Date::today('UTC')->startOfDay())->count();
|
||||
}
|
||||
|
||||
return PremiumEmail::count();
|
||||
return PremiumEmail::query()->count();
|
||||
}
|
||||
|
||||
private function getOpenTicketsCount(string $period = 'today'): int
|
||||
private function getOpenTicketsCount(): int
|
||||
{
|
||||
return Ticket::whereIn('status', ['open', 'pending'])->count();
|
||||
return Ticket::query()->whereIn('status', ['open', 'pending'])->count();
|
||||
}
|
||||
|
||||
private function getClosedTicketsCount(string $period = 'today'): int
|
||||
private function getClosedTicketsCount(): int
|
||||
{
|
||||
return Ticket::whereIn('status', ['closed'])->count();
|
||||
return Ticket::query()->whereIn('status', ['closed'])->count();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user