Skip to content

Commit

Permalink
upgrade filament3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cklei-carly committed Aug 8, 2023
1 parent 71a96bd commit 658d7f2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 44 deletions.
25 changes: 15 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@
"require": {
"php": "^8.0",
"akaunting/laravel-firewall": "^2.1",
"filament/filament": "^2.0",
"spatie/laravel-package-tools": "^1.13.5"
"filament/filament": "^3.0",
"filament/support": "^3.0",
"spatie/laravel-package-tools": "^1.15.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.0",
"nunomaduro/collision": "^7.9",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"pestphp/pest-plugin-livewire": "^1.0",
"pestphp/pest-plugin-parallel": "^0.3",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-arch": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"spatie/laravel-ray": "^1.26"
},
"autoload": {
Expand All @@ -59,5 +58,11 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
}
}
28 changes: 13 additions & 15 deletions src/Filament/Resources/FirewallIpResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace SolutionForest\FilamentFirewall\Filament\Resources;

use Filament\Forms;
use Filament\Resources\Form;
use Filament\Forms\Form;
use Filament\Forms\Set;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\Request;
Expand All @@ -24,10 +25,10 @@ public static function form(Form $form): Form
->default(fn () => Request::getClientIp())
->regex('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/')
->validationAttribute(Str::upper(__('filament-firewall::filament-firewall.form.field.ip')))
->suffixAction(fn (callable $set) => Forms\Components\Actions\Action::make('fillMyIp')
->suffixAction(Forms\Components\Actions\Action::make('fillMyIp')
->label(__('filament-firewall::filament-firewall.action.fillMyIp'))
->icon('heroicon-o-pencil-alt')
->action(fn () => $set('ip', Request::getClientIp()))
->icon('heroicon-o-pencil')
->action(fn (Set $set) => $set('ip', Request::getClientIp()))
)
->required(),

Expand Down Expand Up @@ -64,14 +65,11 @@ public static function table(Table $table): Table
->sortable(),
Tables\Columns\IconColumn::make('blocked')
->label(__('filament-firewall::filament-firewall.table.column.is_allow'))
->options([
'heroicon-o-x-circle' => fn (bool $record) => boolval($record),
'heroicon-o-check-circle' => fn (bool $record) => ! boolval($record),
])
->colors([
'danger' => fn (bool $record) => boolval($record),
'success' => fn (bool $record) => ! boolval($record),
]),
->boolean()
->falseIcon('heroicon-o-check-circle')
->falseColor('success')
->trueIcon('heroicon-o-x-circle')
->trueColor('danger'),
Tables\Columns\TextColumn::make('created_at')
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
Expand Down Expand Up @@ -105,7 +103,7 @@ public static function getModel(): string
return config('filament-firewall.models.ip', \SolutionForest\FilamentFirewall\Models\Ip::class);
}

protected static function getNavigationLabel(): string
public static function getNavigationLabel(): string
{
return __('filament-firewall::filament-firewall.filament.resource.ip.navigationLabel');
}
Expand All @@ -130,7 +128,7 @@ public static function getPluralModelLabel(): string
return __('filament-firewall::filament-firewall.filament.resource.ip.pluralModelLabel');
}

protected static function getNavigationGroup(): ?string
public static function getNavigationGroup(): ?string
{
return __('filament-firewall::filament-firewall.filament.resource.ip.getNavigationGroup');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace SolutionForest\FilamentFirewall\Filament\Resources\FirewallIpResource\Pages;

use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ManageRecords;
use Filament\Support\Exceptions\Halt;
use Illuminate\Support\Facades\Request;
use SolutionForest\FilamentFirewall\Facades\FilamentFirewall;
use SolutionForest\FilamentFirewall\Filament\Resources\FirewallIpResource;
Expand All @@ -17,11 +18,11 @@ class ManageFirewallIps extends ManageRecords
protected function getActions(): array
{
return [
Actions\Action::make('addMyIp')
Action::make('addMyIp')
->label(__('filament-firewall::filament-firewall.action.addMyIp'))
->action('addMyIp'),
Actions\CreateAction::make()
->label(__('filament-support::actions/create.single.label', ['label' => null])),
CreateAction::make()
->label(__('filament-actions::create.single.label', ['label' => null])),
];
}

Expand All @@ -40,18 +41,28 @@ public function addMyIp()
return;
}

$this->handleRecordCreation([
$data = [
'ip' => $currIp,
'blocked' => false,
]);

];

$record = new ($this->getModel())($data);

if ($tenant = Filament::getTenant()) {
$record = $this->associateRecordWithTenant($record, $tenant);

} else {

$record->save();
}

Notification::make()
->title($this->getCreatedNotificationMessage())
->title(__('filament-actions::create.single.notifications.created.title'))
->success()
->send();

} catch (\Exception $e) {

//
}
}
}
35 changes: 35 additions & 0 deletions src/FilamentFirewallPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace SolutionForest\FilamentFirewall;

use Filament\Contracts\Plugin;
use Filament\Panel;

class FilamentFirewallPanel implements Plugin
{
public function getId(): string
{
return 'filament-firewall-plugin';
}

public function register(Panel $panel): void
{
$resources = config('filament-firewall.resources', []);
$panel->resources($resources);
}

public function boot(Panel $panel): void
{
//
}

public static function make(): static
{
return app(static::class);
}

public static function get(): static
{
return filament(app(static::class)->getId());
}
}
11 changes: 2 additions & 9 deletions src/FilamentFirewallServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace SolutionForest\FilamentFirewall;

use Carbon\Carbon;
use Filament\PluginServiceProvider;
use SolutionForest\FilamentFirewall\Filament\Resources\FirewallIpResource;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class FilamentFirewallServiceProvider extends PluginServiceProvider
class FilamentFirewallServiceProvider extends PackageServiceProvider
{
public static string $name = 'filament-firewall';

Expand All @@ -35,9 +33,4 @@ public function configurePackage(Package $package): void
});
});
}

public function getResources(): array
{
return config('filament-firewall.resources', []);
}
}

0 comments on commit 658d7f2

Please sign in to comment.