From dbdf0cb20e98d7e9b02c1bad46d37598d9cdcb26 Mon Sep 17 00:00:00 2001 From: zhaiyuxin103 Date: Tue, 17 Dec 2024 22:55:58 +0800 Subject: [PATCH] refactor(admin & role): rename order field to sort --- _ide_helper_models.php | 9 ++++----- app/Filament/Resources/AdminResource.php | 8 ++++---- app/Filament/Resources/Shield/RoleResource.php | 6 +++--- .../Resources/Shield/RoleResource/Pages/CreateRole.php | 2 +- .../Resources/Shield/RoleResource/Pages/EditRole.php | 2 +- app/Models/Admin.php | 2 +- app/Models/Role.php | 2 +- app/Policies/RolePolicy.php | 2 +- .../migrations/2024_12_10_151839_create_admins_table.php | 2 +- .../2024_12_12_145534_add_description_to_roles_table.php | 4 ++-- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/_ide_helper_models.php b/_ide_helper_models.php index 8eab591..956a8c3 100644 --- a/_ide_helper_models.php +++ b/_ide_helper_models.php @@ -74,7 +74,7 @@ class IdeHelperAbout {} * @property string|null $last_actived_at 最后活跃时间 * @property string|null $remember_token * @property bool $state 状态 - * @property int $order 排序 + * @property int $sort 排序 * @property \Illuminate\Support\Carbon|null $deleted_at * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at @@ -117,10 +117,10 @@ class IdeHelperAbout {} * @method static \Illuminate\Database\Eloquent\Builder|Admin whereLastAuthedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Admin whereLastName($value) * @method static \Illuminate\Database\Eloquent\Builder|Admin whereNotificationCount($value) - * @method static \Illuminate\Database\Eloquent\Builder|Admin whereOrder($value) * @method static \Illuminate\Database\Eloquent\Builder|Admin wherePassword($value) * @method static \Illuminate\Database\Eloquent\Builder|Admin wherePhone($value) * @method static \Illuminate\Database\Eloquent\Builder|Admin whereRememberToken($value) + * @method static \Illuminate\Database\Eloquent\Builder|Admin whereSort($value) * @method static \Illuminate\Database\Eloquent\Builder|Admin whereState($value) * @method static \Illuminate\Database\Eloquent\Builder|Admin whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Admin withTrashed() @@ -339,7 +339,7 @@ class IdeHelperPrivacy {} * @property \Illuminate\Support\Carbon|null $updated_at * @property string|null $description * @property bool $state 状态 - * @property int $order 排序 + * @property int $sort 排序 * @property \Illuminate\Support\Carbon|null $deleted_at * @property-read \Illuminate\Database\Eloquent\Collection $permissions * @property-read int|null $permissions_count @@ -356,7 +356,7 @@ class IdeHelperPrivacy {} * @method static \Illuminate\Database\Eloquent\Builder|Role whereGuardName($value) * @method static \Illuminate\Database\Eloquent\Builder|Role whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Role whereName($value) - * @method static \Illuminate\Database\Eloquent\Builder|Role whereOrder($value) + * @method static \Illuminate\Database\Eloquent\Builder|Role whereSort($value) * @method static \Illuminate\Database\Eloquent\Builder|Role whereState($value) * @method static \Illuminate\Database\Eloquent\Builder|Role whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Role withTrashed() @@ -564,7 +564,6 @@ class IdeHelperUser {} * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $deleted_at - * @property-read \App\Models\User|null $user * @method static \Illuminate\Database\Eloquent\Builder|VerificationCode newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|VerificationCode newQuery() * @method static \Illuminate\Database\Eloquent\Builder|VerificationCode onlyTrashed() diff --git a/app/Filament/Resources/AdminResource.php b/app/Filament/Resources/AdminResource.php index 1dcb55e..fe54497 100644 --- a/app/Filament/Resources/AdminResource.php +++ b/app/Filament/Resources/AdminResource.php @@ -113,11 +113,11 @@ public static function form(Form $form): Form ->required() ->default(true) ->label(trans('fields.state')), - Forms\Components\TextInput::make('order') + Forms\Components\TextInput::make('sort') ->required() ->numeric() ->default(0) - ->label(trans('fields.order')), + ->label(trans('fields.sort')), ]), Forms\Components\Placeholder::make('created_at') ->content(fn (?Admin $record): string => $record?->created_at?->diffForHumans() ?? '-') @@ -182,10 +182,10 @@ public static function table(Table $table): Table Tables\Columns\IconColumn::make('state') ->boolean() ->label(trans('fields.state')), - Tables\Columns\TextColumn::make('order') + Tables\Columns\TextColumn::make('sort') ->numeric() ->sortable() - ->label(trans('fields.order')), + ->label(trans('fields.sort')), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable() diff --git a/app/Filament/Resources/Shield/RoleResource.php b/app/Filament/Resources/Shield/RoleResource.php index 1c03825..258cd80 100644 --- a/app/Filament/Resources/Shield/RoleResource.php +++ b/app/Filament/Resources/Shield/RoleResource.php @@ -83,7 +83,7 @@ public static function form(Form $form): Form ->required() ->default(true) ->label(trans('fields.state')), - Forms\Components\TextInput::make('order') + Forms\Components\TextInput::make('sort') ->required() ->numeric() ->default(0) @@ -131,10 +131,10 @@ public static function table(Table $table): Table Tables\Columns\IconColumn::make('state') ->boolean() ->label(trans('fields.state')), - Tables\Columns\TextColumn::make('order') + Tables\Columns\TextColumn::make('sort') ->numeric() ->sortable() - ->label(trans('fields.order')), + ->label(trans('fields.sort')), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable() diff --git a/app/Filament/Resources/Shield/RoleResource/Pages/CreateRole.php b/app/Filament/Resources/Shield/RoleResource/Pages/CreateRole.php index 2953015..a39142e 100644 --- a/app/Filament/Resources/Shield/RoleResource/Pages/CreateRole.php +++ b/app/Filament/Resources/Shield/RoleResource/Pages/CreateRole.php @@ -32,7 +32,7 @@ protected function mutateFormDataBeforeCreate(array $data): array ->flatten() ->unique(); - return Arr::only($data, ['name', 'guard_name', 'description', 'state', 'order']); + return Arr::only($data, ['name', 'guard_name', 'description', 'state', 'sort']); } protected function afterCreate(): void diff --git a/app/Filament/Resources/Shield/RoleResource/Pages/EditRole.php b/app/Filament/Resources/Shield/RoleResource/Pages/EditRole.php index ed1d1e7..2106118 100644 --- a/app/Filament/Resources/Shield/RoleResource/Pages/EditRole.php +++ b/app/Filament/Resources/Shield/RoleResource/Pages/EditRole.php @@ -62,7 +62,7 @@ protected function mutateFormDataBeforeSave(array $data): array ->flatten() ->unique(); - return Arr::only($data, ['name', 'guard_name', 'description', 'state', 'order']); + return Arr::only($data, ['name', 'guard_name', 'description', 'state', 'sort']); } protected function afterSave(): void diff --git a/app/Models/Admin.php b/app/Models/Admin.php index f432f9d..459b453 100644 --- a/app/Models/Admin.php +++ b/app/Models/Admin.php @@ -57,7 +57,7 @@ class Admin extends Authenticatable implements FilamentUser, HasAvatar, HasName 'age', 'introduction', 'state', - 'order', + 'sort', ]; public function canAccessPanel(Panel $panel): bool diff --git a/app/Models/Role.php b/app/Models/Role.php index 1b77a73..f147066 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -24,7 +24,7 @@ class Role extends SpatieRole 'guard_name', 'description', 'state', - 'order', + 'sort', ]; /** diff --git a/app/Policies/RolePolicy.php b/app/Policies/RolePolicy.php index e41931c..d7badb4 100644 --- a/app/Policies/RolePolicy.php +++ b/app/Policies/RolePolicy.php @@ -5,8 +5,8 @@ namespace App\Policies; use App\Models\Admin; +use App\Models\Role; use Illuminate\Auth\Access\HandlesAuthorization; -use Spatie\Permission\Models\Role; class RolePolicy { diff --git a/database/migrations/2024_12_10_151839_create_admins_table.php b/database/migrations/2024_12_10_151839_create_admins_table.php index 0492d83..fa0b665 100644 --- a/database/migrations/2024_12_10_151839_create_admins_table.php +++ b/database/migrations/2024_12_10_151839_create_admins_table.php @@ -35,7 +35,7 @@ public function up(): void $table->timestamp('last_actived_at')->nullable()->comment('最后活跃时间'); $table->rememberToken(); $table->boolean('state')->default(true)->comment('状态'); - $table->unsignedBigInteger('order')->default(0)->comment('排序'); + $table->unsignedBigInteger('sort')->default(0)->comment('排序'); $table->softDeletesTz(); $table->timestampsTz(); }); diff --git a/database/migrations/2024_12_12_145534_add_description_to_roles_table.php b/database/migrations/2024_12_12_145534_add_description_to_roles_table.php index af240ec..791cb27 100644 --- a/database/migrations/2024_12_12_145534_add_description_to_roles_table.php +++ b/database/migrations/2024_12_12_145534_add_description_to_roles_table.php @@ -16,7 +16,7 @@ public function up(): void Schema::table('roles', function (Blueprint $table) { $table->string('description')->nullable(); $table->boolean('state')->default(true)->comment('状态'); - $table->unsignedInteger('order')->default(0)->comment('排序'); + $table->unsignedInteger('sort')->default(0)->comment('排序'); $table->softDeletesTz(); }); } @@ -27,7 +27,7 @@ public function up(): void public function down(): void { Schema::table('roles', function (Blueprint $table) { - $table->dropColumn(['description', 'state', 'order', 'deleted_at']); + $table->dropColumn(['description', 'state', 'sort', 'deleted_at']); }); } };