Skip to content

Commit f58e9b1

Browse files
authored
Merge pull request #5 from DutchCodingCompany/add-switch-to-button
Add switch to button when logged in
2 parents f4ca350 + a9719d6 commit f58e9b1

18 files changed

+330
-72
lines changed

.github/workflows/phpstan.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ on:
66
- '**.php'
77
- '.github/workflows/phpstan.yml'
88
- 'phpstan.neon.dist'
9-
pull_request:
9+
pull_request:
10+
branches:
11+
- '**'
1012

1113
jobs:
1214
phpstan:

.github/workflows/run-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
- 'composer.json'
1010
- 'composer.lock'
1111
pull_request:
12+
branches:
13+
- '**'
1214

1315
jobs:
1416
test:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `dutchcodingcompany/developer-logins` will be documented in this file.
44

5+
## 1.1.0 - 2024-05-03
6+
7+
- Added a "Switch to" button to the top right of the page when you are logged in. This button allows you to switch to another user without having to log out first.
8+
59
## 1.0.0 - 2024-04-25
610

711
- initial release

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ FilamentDeveloperLoginsPlugin::make()
5151
->enabled(app()->environment('local'))
5252
```
5353

54+
### switchable()
55+
56+
By default, a "Switch to" button is shown in the top right corner of the screen, so you can easily switch between the provided users.
57+
If you want to disable this feature, you can use the switchable() method.
58+
59+
```php
60+
// ...
61+
FilamentDeveloperLoginsPlugin::make()
62+
->switchable(false) // This also accepts a closure.
63+
```
64+
65+
![example-screenshot.png](docs-assets/screenshots/switchable-screenshot.png)
66+
5467
### column()
5568

5669
By default, the user column is set to `email`. If you want to use a different column, you can use the column() method.
17.6 KB
Loading

phpstan-baseline.neon

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ parameters:
1313
-
1414
message: "#^Call to an undefined method object\\:\\:where\\(\\)\\.$#"
1515
count: 1
16-
path: src/Http/Controllers/DeveloperLoginsController.php
16+
path: src/FilamentDevelopersLogin.php
17+
18+
-
19+
message: "#^Call to an undefined method Livewire\\\\Features\\\\SupportTesting\\\\Testable\\:\\:test\\(\\)\\.$#"
20+
count: 3
21+
path: tests/Feature/MenuLoginsTest.php
1722

1823
-
1924
message: "#^Access to an undefined property DutchCodingCompany\\\\FilamentDeveloperLogins\\\\Tests\\\\Fixtures\\\\TestUser\\:\\:\\$is_admin\\.$#"

resources/lang/en/auth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
return [
44
'login-as' => 'Login as',
5+
'switch-to' => 'Switch to',
56

67
'messages' => [
78
'failed' => 'Login failed, check if the user is allowed to access the panel.',

resources/views/components/developer-logins.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@foreach ($users as $label => $email)
1+
@foreach ($users as $label => $credentials)
22
@if ($loop->first)
33
<div class="flex flex-col gap-y-6">
44
<div class="relative flex items-center justify-center text-center">
@@ -22,10 +22,10 @@
2222
@csrf
2323

2424
<input type="hidden" name="panel_id" value="{{ \Filament\Facades\Filament::getId() }}">
25-
<input type="hidden" name="credentials" value="{{ $email }}">
25+
<input type="hidden" name="credentials" value="{{ $credentials }}">
2626

2727
<x-filament::button class="w-full" color="gray" outlined="true" type="submit">
28-
{{ "$label ($email)" }}
28+
{{ "$label ($credentials)" }}
2929
</x-filament::button>
3030
</form>
3131
@if ($loop->first)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@if (filled($users))
2+
<div>
3+
<x-filament::dropdown>
4+
<x-slot name="trigger">
5+
<x-filament::button icon="heroicon-o-user" color="gray" outlined="false">
6+
{{ __('filament-developer-logins::auth.switch-to') }}
7+
</x-filament::button>
8+
</x-slot>
9+
10+
<x-filament::dropdown.list>
11+
@foreach ($users as $label => $credentials)
12+
<x-filament::dropdown.list.item
13+
wire:click="loginAs('{{ $credentials }}')"
14+
color="{{ $credentials === $current ? 'primary' : 'gray' }}"
15+
>
16+
{{ "$label ($credentials)" }}
17+
</x-filament::dropdown.list.item>
18+
@endforeach
19+
</x-filament::dropdown.list>
20+
</x-filament::dropdown>
21+
</div>
22+
@endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace DutchCodingCompany\FilamentDeveloperLogins\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
/**
8+
* @mixin \DutchCodingCompany\FilamentDeveloperLogins\FilamentDevelopersLogin
9+
*/
10+
class FilamentDevelopersLogin extends Facade
11+
{
12+
protected static function getFacadeAccessor(): string
13+
{
14+
return 'filament-developers-login';
15+
}
16+
}

0 commit comments

Comments
 (0)