diff --git a/app/Filament/Resources/PluginBundleResource.php b/app/Filament/Resources/PluginBundleResource.php index a0e2781f..ace52b5b 100644 --- a/app/Filament/Resources/PluginBundleResource.php +++ b/app/Filament/Resources/PluginBundleResource.php @@ -189,10 +189,10 @@ public static function table(Table $table): Table ->orWhere('email', 'like', "%{$search}%") ->limit(50) ->get() - ->mapWithKeys(fn (User $user) => [$user->id => "{$user->name} ({$user->email})"]) + ->mapWithKeys(fn (User $user) => [$user->id => "{$user->getFilamentName()} ({$user->email})"]) ->toArray(); }) - ->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name) + ->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->getFilamentName()) ->required(), ]) ->action(function (PluginBundle $record, array $data): void { diff --git a/tests/Feature/Filament/GrantBundleToUserActionTest.php b/tests/Feature/Filament/GrantBundleToUserActionTest.php index 43d2237c..4e494d16 100644 --- a/tests/Feature/Filament/GrantBundleToUserActionTest.php +++ b/tests/Feature/Filament/GrantBundleToUserActionTest.php @@ -51,4 +51,25 @@ public function test_grant_to_user_action_can_be_called_with_user_id(): void ]); } } + + public function test_grant_to_user_action_works_for_user_with_null_name(): void + { + $recipient = User::factory()->create(['name' => null]); + $plugins = Plugin::factory()->count(1)->approved()->create(); + $this->bundle->plugins()->attach($plugins->pluck('id')); + + Livewire::actingAs($this->admin) + ->test(ListPluginBundles::class) + ->callAction( + TestAction::make('grantToUser')->table($this->bundle), + data: ['user_id' => $recipient->id], + ) + ->assertHasNoFormErrors(); + + $this->assertDatabaseHas('plugin_licenses', [ + 'user_id' => $recipient->id, + 'plugin_id' => $plugins->first()->id, + 'plugin_bundle_id' => $this->bundle->id, + ]); + } }