Skip to content

Commit 0fe9446

Browse files
authored
Merge pull request #22 from mathieutu/patch-1
Allow passing a closure for users.
2 parents 460bc5f + 731371a commit 0fe9446

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Register the plugin in the Filament panel provider (the default file is `app/Pro
2323

2424
In the `users` method you can define the users (note: the users must exist), the key is used as a label on the login button and the value is used to search the user in the database.
2525

26+
2627
```php
2728
// ...
2829
->plugins([
@@ -35,6 +36,15 @@ In the `users` method you can define the users (note: the users must exist), the
3536
]);
3637
```
3738

39+
The users() method can also be passed a closure to compute the users list at render time, for example from the database.
40+
41+
```php
42+
// ...
43+
FilamentDeveloperLoginsPlugin::make()
44+
->users(fn () => User::pluck('email', 'name')->toArray())
45+
]);
46+
```
47+
3848
## Customization
3949

4050
### enabled()
@@ -113,7 +123,7 @@ FilamentDeveloperLoginsPlugin::make()
113123
->modelClass(Admin::class)
114124
```
115125

116-
### RedirectTo()
126+
### redirectTo()
117127

118128
By default, the user will be redirected using the `Filament::getUrl()` method, which directs them to the dashboard. In the case of multi-tenancy, the user will also be redirected to the correct tenant. If you prefer to use a different url, you can utilize the redirectTo() method.
119129

src/FilamentDeveloperLoginsPlugin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FilamentDeveloperLoginsPlugin implements Plugin
2323
/**
2424
* @var array<string, string>
2525
*/
26-
public array $users = [];
26+
public Closure | array $users = [];
2727

2828
public Closure | string | null $redirectTo = null;
2929

@@ -105,11 +105,11 @@ public function getSwitchable(): bool
105105
}
106106

107107
/**
108-
* @param array<string, string> $users
108+
* @param Closure | array<string, string> $users
109109
*
110110
* @return $this
111111
*/
112-
public function users(array $users): static
112+
public function users(Closure | array $users): static
113113
{
114114
$this->users = $users;
115115

@@ -121,7 +121,7 @@ public function users(array $users): static
121121
*/
122122
public function getUsers(): array
123123
{
124-
return $this->users;
124+
return $this->evaluate($this->users);
125125
}
126126

127127
public function redirectTo(Closure | string $redirectTo): static

0 commit comments

Comments
 (0)