diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 0000000..2982143
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -0,0 +1,35 @@
+name: Tests
+
+on:
+ push:
+ branches: [main]
+ pull_request:
+ branches: [main]
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: true
+ matrix:
+ php: [8.2, 8.3, 8.4]
+
+ name: PHP ${{ matrix.php }}
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
+ coverage: none
+
+ - name: Install dependencies
+ run: composer install --prefer-dist --no-interaction --no-progress
+
+ - name: Run tests
+ run: vendor/bin/pest
diff --git a/.gitignore b/.gitignore
index cb756e9..e12d770 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
vendor
-.idea
\ No newline at end of file
+.idea
+.phpunit.cache
diff --git a/CLAUDE.md b/CLAUDE.md
index 1a57d6a..2fd77c3 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -32,6 +32,15 @@ The `accessToken` can be set:
1. **Globally** via `config/filament-userback.php` - applies to all panels
2. **Per-panel** via `->accessToken()` method - overrides global config
+The `only_authenticated` setting controls whether the widget is shown only to authenticated users:
+1. **Globally** via `config/filament-userback.php` (default: `true`)
+2. **Per-panel** via `->onlyAuthenticated()` method - overrides global config
+
+The `guard` setting specifies which authentication guard to use:
+1. **Per-panel** via `->guard()` method - highest priority
+2. **Globally** via `config/filament-userback.php`
+3. **Fallback** to the panel's configured auth guard (`$panel->getAuthGuard()`)
+
## Common Tasks
### Testing the plugin locally
diff --git a/composer.json b/composer.json
index 00d9c71..01b0d7d 100644
--- a/composer.json
+++ b/composer.json
@@ -15,11 +15,21 @@
"illuminate/contracts": "^11.0|^12.0",
"spatie/laravel-package-tools": "^1.16"
},
+ "require-dev": {
+ "orchestra/testbench": "^9.0|^10.0",
+ "pestphp/pest": "^3.0",
+ "pestphp/pest-plugin-laravel": "^3.0"
+ },
"autoload": {
"psr-4": {
"CoddinWeb\\FilamentUserback\\": "src/"
}
},
+ "autoload-dev": {
+ "psr-4": {
+ "CoddinWeb\\FilamentUserback\\Tests\\": "tests/"
+ }
+ },
"extra": {
"laravel": {
"providers": [
@@ -27,6 +37,14 @@
]
}
},
+ "scripts": {
+ "test": "vendor/bin/pest"
+ },
+ "config": {
+ "allow-plugins": {
+ "pestphp/pest-plugin": true
+ }
+ },
"minimum-stability": "dev",
"prefer-stable": true
}
diff --git a/config/filament-userback.php b/config/filament-userback.php
index 422ea6c..5864062 100644
--- a/config/filament-userback.php
+++ b/config/filament-userback.php
@@ -17,4 +17,32 @@
*/
'access_token' => env('USERBACK_ACCESS_TOKEN'),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Only Authenticated Users
+ |--------------------------------------------------------------------------
+ |
+ | When set to true, the Userback widget will only be rendered for
+ | authenticated users. Set to false to show the widget to all visitors.
+ |
+ | This can be overridden per-panel using the ->onlyAuthenticated() method.
+ |
+ */
+
+ 'only_authenticated' => env('USERBACK_ONLY_AUTHENTICATED', true),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Authentication Guard
+ |--------------------------------------------------------------------------
+ |
+ | The authentication guard to use when checking if a user is authenticated.
+ | If not set, it will fall back to the panel's configured auth guard.
+ |
+ | This can be overridden per-panel using the ->guard() method.
+ |
+ */
+
+ 'guard' => env('USERBACK_GUARD'),
];
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..8848452
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,18 @@
+
+
+
+
+ tests
+
+
+
+
+ src
+
+
+
diff --git a/resources/views/userback.blade.php b/resources/views/userback.blade.php
index 4cd7989..bbef6e3 100644
--- a/resources/views/userback.blade.php
+++ b/resources/views/userback.blade.php
@@ -1,4 +1,4 @@
-@if(\is_string($accessToken))
+@if(\is_string($accessToken) && (!$onlyAuthenticated || auth($guard)->check()))