Skip to content

Commit acfff7e

Browse files
committed
Allow the redirectTo method to accept a closure
1 parent 1dd62c1 commit acfff7e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,18 @@ FilamentDeveloperLoginsPlugin::make()
8888

8989
### RedirectTo()
9090

91-
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 route, you can utilize the redirectTo() method.
91+
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.
92+
93+
```php
94+
FilamentDeveloperLoginsPlugin::make()
95+
->redirectTo('/custom-url')
96+
```
97+
98+
Since the routes are not yet registered when the plugin is created, you need to use a closure to redirect to a named route.
99+
92100
```php
93101
FilamentDeveloperLoginsPlugin::make()
94-
->redirectTo('/custom-route')
102+
->redirectTo(fn () => route('custom.route'))
95103
```
96104

97105
## Testing

src/FilamentDeveloperLoginsPlugin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FilamentDeveloperLoginsPlugin implements Plugin
2424
*/
2525
public array $users = [];
2626

27-
public ?string $redirectTo = null;
27+
public Closure | string | null $redirectTo = null;
2828

2929
public ?string $panelId = null;
3030

@@ -120,16 +120,16 @@ public function getUsers(): array
120120
return $this->users;
121121
}
122122

123-
public function redirectTo(string $routeName): static
123+
public function redirectTo(Closure | string $redirectTo): static
124124
{
125-
$this->redirectTo = $routeName;
125+
$this->redirectTo = $redirectTo;
126126

127127
return $this;
128128
}
129129

130130
public function getRedirectTo(): string | null
131131
{
132-
return $this->redirectTo;
132+
return $this->evaluate($this->redirectTo);
133133
}
134134

135135
public function column(string $column): static

src/FilamentDevelopersLogin.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public function login(Panel $panel, FilamentDeveloperLoginsPlugin $plugin, strin
4141
session()->regenerate();
4242

4343
return redirect()
44-
->to(
45-
$plugin->getRedirectTo() ?? $panel->getUrl()
46-
);
44+
->to($plugin->getRedirectTo() ?? $panel->getUrl());
4745
}
4846
}

0 commit comments

Comments
 (0)