From da452eb155536fdb421b3372108abbc250912988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9as=20Lundgren?= Date: Mon, 25 Nov 2024 10:01:45 +0100 Subject: [PATCH] Update `firstname` `lastname` to have underscores --- packages/admin/README.md | 2 +- .../admin/database/factories/StaffFactory.php | 4 ++-- ...000_rename_name_columns_on_staff_table.php | 24 +++++++++++++++++++ packages/admin/resources/lang/en/staff.php | 8 +++---- packages/admin/resources/lang/es/staff.php | 8 +++---- packages/admin/resources/lang/fr/staff.php | 8 +++---- packages/admin/resources/lang/nl/staff.php | 8 +++---- .../Commands/MakeLunarAdminCommand.php | 4 ++-- .../src/Filament/Resources/StaffResource.php | 16 ++++++------- packages/admin/src/Models/Staff.php | 12 +++++----- .../StaffResource/Pages/CreateStaffTest.php | 4 ++-- .../StaffResource/Pages/EditStaffTest.php | 12 +++++----- tests/admin/Unit/Models/StaffTest.php | 17 +++++++------ 13 files changed, 75 insertions(+), 52 deletions(-) create mode 100644 packages/admin/database/migrations/2024_11_25_110000_rename_name_columns_on_staff_table.php diff --git a/packages/admin/README.md b/packages/admin/README.md index d48aaf62a3..6827a25ba9 100644 --- a/packages/admin/README.md +++ b/packages/admin/README.md @@ -13,7 +13,7 @@ See the docs at https://lunar-panel.vercel.app/ - [ ] Tax Zone types are "country", "states", "postcodes" -> would prefer it to be "countries" so it's consistent - [ ] `ListField` FieldType shouldn't really have "Field" in its name -> change to simply "List" - [ ] Sometimes we use "Enabled" other times "Active". Do we want to consider consistency here also? -- [ ] Staff "firstname" "lastname" I think should have underscores, e.g. "first_name" +- [x] Staff "firstname" "lastname" I think should have underscores, e.g. "first_name" - [x] How to allow devs to extend Lunar's forms and tables - [x] How to allow devs to overide validation rules - [x] Allow devs to extend by adding their own pages/resources diff --git a/packages/admin/database/factories/StaffFactory.php b/packages/admin/database/factories/StaffFactory.php index 0b50dfc9ea..3300af96ac 100644 --- a/packages/admin/database/factories/StaffFactory.php +++ b/packages/admin/database/factories/StaffFactory.php @@ -20,8 +20,8 @@ class StaffFactory extends Factory public function definition(): array { return [ - 'firstname' => $this->faker->firstName(), - 'lastname' => $this->faker->lastName(), + 'first_name' => $this->faker->firstName(), + 'last_name' => $this->faker->lastName(), 'admin' => $this->faker->boolean(5), 'email' => $this->faker->unique()->safeEmail(), 'email_verified_at' => now(), diff --git a/packages/admin/database/migrations/2024_11_25_110000_rename_name_columns_on_staff_table.php b/packages/admin/database/migrations/2024_11_25_110000_rename_name_columns_on_staff_table.php new file mode 100644 index 0000000000..17b1ab675b --- /dev/null +++ b/packages/admin/database/migrations/2024_11_25_110000_rename_name_columns_on_staff_table.php @@ -0,0 +1,24 @@ +prefix.'staff', function (Blueprint $table) { + $table->renameColumn('firstname', 'first_name'); + $table->renameColumn('lastname', 'last_name'); + }); + } + + public function down(): void + { + Schema::table($this->prefix.'staff', function (Blueprint $table) { + $table->renameColumn('first_name', 'firstname'); + $table->renameColumn('last_name', 'lastname'); + }); + } +}; diff --git a/packages/admin/resources/lang/en/staff.php b/packages/admin/resources/lang/en/staff.php index 5679833c40..d5b6e43a09 100644 --- a/packages/admin/resources/lang/en/staff.php +++ b/packages/admin/resources/lang/en/staff.php @@ -7,10 +7,10 @@ 'plural_label' => 'Staff', 'table' => [ - 'firstname' => [ + 'first_name' => [ 'label' => 'First Name', ], - 'lastname' => [ + 'last_name' => [ 'label' => 'Last Name', ], 'email' => [ @@ -22,10 +22,10 @@ ], 'form' => [ - 'firstname' => [ + 'first_name' => [ 'label' => 'First Name', ], - 'lastname' => [ + 'last_name' => [ 'label' => 'Last Name', ], 'email' => [ diff --git a/packages/admin/resources/lang/es/staff.php b/packages/admin/resources/lang/es/staff.php index bb244d3cc8..b1029457e7 100644 --- a/packages/admin/resources/lang/es/staff.php +++ b/packages/admin/resources/lang/es/staff.php @@ -7,10 +7,10 @@ 'plural_label' => 'Personal', 'table' => [ - 'firstname' => [ + 'first_name' => [ 'label' => 'Nombre', ], - 'lastname' => [ + 'last_name' => [ 'label' => 'Apellido', ], 'email' => [ @@ -22,10 +22,10 @@ ], 'form' => [ - 'firstname' => [ + 'first_name' => [ 'label' => 'Nombre', ], - 'lastname' => [ + 'last_name' => [ 'label' => 'Apellido', ], 'email' => [ diff --git a/packages/admin/resources/lang/fr/staff.php b/packages/admin/resources/lang/fr/staff.php index 14d8ae4feb..a163cba370 100644 --- a/packages/admin/resources/lang/fr/staff.php +++ b/packages/admin/resources/lang/fr/staff.php @@ -7,10 +7,10 @@ 'plural_label' => 'Personnel', 'table' => [ - 'firstname' => [ + 'first_name' => [ 'label' => 'Prénom', ], - 'lastname' => [ + 'last_name' => [ 'label' => 'Nom de famille', ], 'email' => [ @@ -22,10 +22,10 @@ ], 'form' => [ - 'firstname' => [ + 'first_name' => [ 'label' => 'Prénom', ], - 'lastname' => [ + 'last_name' => [ 'label' => 'Nom de famille', ], 'email' => [ diff --git a/packages/admin/resources/lang/nl/staff.php b/packages/admin/resources/lang/nl/staff.php index bf9add60b6..178a965d2f 100644 --- a/packages/admin/resources/lang/nl/staff.php +++ b/packages/admin/resources/lang/nl/staff.php @@ -7,10 +7,10 @@ 'plural_label' => 'Personeel', 'table' => [ - 'firstname' => [ + 'first_name' => [ 'label' => 'Voornaam', ], - 'lastname' => [ + 'last_name' => [ 'label' => 'Achternaam', ], 'email' => [ @@ -22,10 +22,10 @@ ], 'form' => [ - 'firstname' => [ + 'first_name' => [ 'label' => 'Voornaam', ], - 'lastname' => [ + 'last_name' => [ 'label' => 'Achternaam', ], 'email' => [ diff --git a/packages/admin/src/Console/Commands/MakeLunarAdminCommand.php b/packages/admin/src/Console/Commands/MakeLunarAdminCommand.php index 0b48d126fc..7e8bd2cba7 100644 --- a/packages/admin/src/Console/Commands/MakeLunarAdminCommand.php +++ b/packages/admin/src/Console/Commands/MakeLunarAdminCommand.php @@ -32,12 +32,12 @@ class MakeLunarAdminCommand extends Command protected function getUserData(): array { return [ - 'firstname' => $this->options['firstname'] ?? text( + 'first_name' => $this->options['firstname'] ?? text( label: 'First Name', required: true, ), - 'lastname' => $this->options['lastname'] ?? text( + 'last_name' => $this->options['lastname'] ?? text( label: 'Last Name', required: true, ), diff --git a/packages/admin/src/Filament/Resources/StaffResource.php b/packages/admin/src/Filament/Resources/StaffResource.php index f383eade58..019744072f 100644 --- a/packages/admin/src/Filament/Resources/StaffResource.php +++ b/packages/admin/src/Filament/Resources/StaffResource.php @@ -63,8 +63,8 @@ protected static function getMainFormComponents(): array protected static function getFirstNameFormComponent(): Component { - return Forms\Components\TextInput::make('firstname') - ->label(__('lunarpanel::staff.form.firstname.label')) + return Forms\Components\TextInput::make('first_name') + ->label(__('lunarpanel::staff.form.first_name.label')) ->required() ->maxLength(255) ->autofocus(); @@ -72,8 +72,8 @@ protected static function getFirstNameFormComponent(): Component protected static function getLastNameFormComponent(): Component { - return Forms\Components\TextInput::make('lastname') - ->label(__('lunarpanel::staff.form.lastname.label')) + return Forms\Components\TextInput::make('last_name') + ->label(__('lunarpanel::staff.form.last_name.label')) ->required() ->maxLength(255) ->autofocus(); @@ -169,10 +169,10 @@ public static function getDefaultTable(Table $table): Table { return $table ->columns([ - Tables\Columns\TextColumn::make('firstname') - ->label(__('lunarpanel::staff.table.firstname.label')), - Tables\Columns\TextColumn::make('lastname') - ->label(__('lunarpanel::staff.table.lastname.label')), + Tables\Columns\TextColumn::make('first_name') + ->label(__('lunarpanel::staff.table.first_name.label')), + Tables\Columns\TextColumn::make('last_name') + ->label(__('lunarpanel::staff.table.last_name.label')), Tables\Columns\TextColumn::make('email') ->label(__('lunarpanel::staff.table.email.label')), Tables\Columns\TextColumn::make('admin') diff --git a/packages/admin/src/Models/Staff.php b/packages/admin/src/Models/Staff.php index 34b6270078..2feac6e4a4 100644 --- a/packages/admin/src/Models/Staff.php +++ b/packages/admin/src/Models/Staff.php @@ -17,8 +17,8 @@ /** * @property int $id * @property bool $admin - * @property string $firstname - * @property string $lastname + * @property string $first_name + * @property string $last_name * @property string $full_name * @property string $email * @property string $password @@ -40,8 +40,8 @@ class Staff extends Authenticatable implements FilamentUser, HasName protected $guard_name = 'staff'; protected $fillable = [ - 'firstname', - 'lastname', + 'first_name', + 'last_name', 'admin', 'email', 'password', @@ -65,7 +65,7 @@ class Staff extends Authenticatable implements FilamentUser, HasName protected function fullName(): Attribute { return Attribute::get( - fn (): string => "{$this->firstname} {$this->lastname}", + fn (): string => "{$this->first_name} {$this->last_name}", ); } @@ -92,7 +92,7 @@ public function scopeSearch(Builder $query, ?string $terms): void } foreach (explode(' ', $terms) as $term) { - $query->whereAny(['email', 'firstname', 'lastname'], 'LIKE', "%{$term}%"); + $query->whereAny(['email', 'first_name', 'last_name'], 'LIKE', "%{$term}%"); } } diff --git a/tests/admin/Feature/Filament/Resources/StaffResource/Pages/CreateStaffTest.php b/tests/admin/Feature/Filament/Resources/StaffResource/Pages/CreateStaffTest.php index 975a498e3e..838364731a 100644 --- a/tests/admin/Feature/Filament/Resources/StaffResource/Pages/CreateStaffTest.php +++ b/tests/admin/Feature/Filament/Resources/StaffResource/Pages/CreateStaffTest.php @@ -22,8 +22,8 @@ $staff->assignRole('staff'); $formData = [ - 'firstname' => $staff->firstname, - 'lastname' => $staff->lastname, + 'first_name' => $staff->first_name, + 'last_name' => $staff->last_name, 'email' => 'test@example.com', 'password' => 'password', ]; diff --git a/tests/admin/Feature/Filament/Resources/StaffResource/Pages/EditStaffTest.php b/tests/admin/Feature/Filament/Resources/StaffResource/Pages/EditStaffTest.php index 59c5c0df3d..d06e1623e2 100644 --- a/tests/admin/Feature/Filament/Resources/StaffResource/Pages/EditStaffTest.php +++ b/tests/admin/Feature/Filament/Resources/StaffResource/Pages/EditStaffTest.php @@ -24,8 +24,8 @@ 'record' => $staff->getRouteKey(), ]) ->assertFormSet([ - 'firstname' => $staff->firstname, - 'lastname' => $staff->lastname, + 'first_name' => $staff->first_name, + 'last_name' => $staff->last_name, 'email' => $staff->email, ]); }); @@ -39,16 +39,16 @@ 'record' => $staff->getRouteKey(), ]) ->fillForm([ - 'firstname' => $newData->firstname, - 'lastname' => $newData->lastname, + 'first_name' => $newData->first_name, + 'last_name' => $newData->last_name, 'email' => $newData->email, ]) ->call('save') ->assertHasNoFormErrors(); expect($staff->refresh()) - ->firstname->toBe($newData->firstname) - ->lastname->toBe($newData->lastname) + ->first_name->toBe($newData->first_name) + ->last_name->toBe($newData->last_name) ->email->toBe($newData->email); }); diff --git a/tests/admin/Unit/Models/StaffTest.php b/tests/admin/Unit/Models/StaffTest.php index 18999929a3..fa4ac00474 100644 --- a/tests/admin/Unit/Models/StaffTest.php +++ b/tests/admin/Unit/Models/StaffTest.php @@ -5,8 +5,8 @@ test('can get full name', function () { $staff = \Lunar\Admin\Models\Staff::factory()->create([ - 'firstname' => 'Joe', - 'lastname' => 'Bloggs', + 'first_name' => 'Joe', + 'last_name' => 'Bloggs', ]); expect($staff->full_name)->toBe('Joe Bloggs'); @@ -14,22 +14,21 @@ test('can search staff by name', function () { \Lunar\Admin\Models\Staff::factory()->create([ - 'firstname' => 'Joe', - 'lastname' => 'Bloggs', + 'first_name' => 'Joe', + 'last_name' => 'Bloggs', ]); \Lunar\Admin\Models\Staff::factory()->create([ - 'firstname' => 'Tim', - 'lastname' => 'Bloggs', + 'first_name' => 'Tim', + 'last_name' => 'Bloggs', ]); \Lunar\Admin\Models\Staff::factory()->create([ - 'firstname' => 'Bill', - 'lastname' => 'Chance', + 'first_name' => 'Bill', + 'last_name' => 'Chance', ]); expect(\Lunar\Admin\Models\Staff::search('Bloggs')->get())->toHaveCount(2) ->and(\Lunar\Admin\Models\Staff::search('Bill')->get())->toHaveCount(1) ->and(\Lunar\Admin\Models\Staff::search('Joe Bloggs')->get())->toHaveCount(1); }); -