danielcristeaa / laravel-simple-surveys
A lightweight, code-first Laravel package for running targeted in-app surveys with a drop-in Blade widget and protected results dashboard.
Package info
github.com/danielCristeaa/laravel-simple-surveys
pkg:composer/danielcristeaa/laravel-simple-surveys
Requires
- php: ^8.2
- illuminate/bus: ^11.0|^12.0|^13.0
- illuminate/console: ^11.0|^12.0|^13.0
- illuminate/contracts: ^11.0|^12.0|^13.0
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/notifications: ^11.0|^12.0|^13.0
- illuminate/queue: ^11.0|^12.0|^13.0
- illuminate/routing: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
- illuminate/translation: ^11.0|^12.0|^13.0
- illuminate/validation: ^11.0|^12.0|^13.0
- illuminate/view: ^11.0|^12.0|^13.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9|^3.0
- laravel/pint: ^1.18
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-arch: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A lightweight, code-first Laravel package for running targeted in-app surveys with a drop-in Blade widget, headless JSON API, and a protected Admin Results Dashboard.
Features
- Code-first fluent API: Define surveys, 8 input types (plus
Question::nps()& ratingscaleLabels()), conditional follow-ups (->when(...)), and scaffoldSurveyDefinitionclasses viaphp artisan make:survey. - Drop-in accessible Blade widget: Mount
<x-simple-surveys::widget />onceāzero JS build step, zero CSS leaks, WCAG AA keyboard/modal/screen-reader support, light/dark/auto themes, 5 placements (including centered modal), and Inertia/LivewiredynamicSPA mode. - Headless JSON API: Built-in rate-limited (
routes.throttle) endpoints for React, Vue, Next.js, Nuxt, or mobile apps over Sanctum/Passport. - Flexible styling: Customize globally or per survey via zero-specificity
--lss-*CSS custom properties, or visually with a live preview in the Admin Appearance tab. - Eloquent & page targeting: Target authenticated users with real Eloquent queries (
where,whereHas), user predicates, route/path rules, schedules, and dismissal re-prompt cooldowns. - Multi-language ready: Publishable widget UI strings, convention-based
lang/{locale}/simple-surveys.phpscaffolding (simple-surveys:translations), and automatic respondentlocalerecording. - Analytics, webhooks, notifications & GDPR: Built-in funnel tracking (seen, opened, abandoned, response/completion rates), browser
CustomEvents, tracking context snapshots, signed webhooks, Mail/Slack submission alerts, andforgetRespondent()/anonymizeRespondent()privacy helpers. - Production-hardened & strictly typed: PHP 8.2+, Laravel 11.x / 12.x / 13.x, Octane-safe, strict CSP nonce support (zero inline
style/event attributes), custom DBconnectionsupport, and PHPStan Level 8+.
Requirements
- PHP
8.2+ - Laravel
11.x,12.x, or13.x
Installation
Install the package via Composer:
composer require danielcristeaa/laravel-simple-surveys
Publish and run the migration:
php artisan vendor:publish --tag="simple-surveys-migrations"
php artisan migrate
Optionally publish the configuration file:
php artisan vendor:publish --tag="simple-surveys-config"
Quick Start
1. Register a Survey
Register a survey in AppServiceProvider::boot() (or a dedicated service provider):
use DanielCristea\SimpleSurveys\Facades\SimpleSurveys; use DanielCristea\SimpleSurveys\Question; use DanielCristea\SimpleSurveys\Survey; use Illuminate\Database\Eloquent\Builder; SimpleSurveys::register( Survey::make('onboarding-feedback') ->title('Quick Onboarding Survey') ->banner('Got 30 seconds? Help us improve onboarding!') ->target(fn (Builder $query) => $query->where('created_at', '<=', now()->subDays(7))) ->questions([ Question::rating('experience', 'How would you rate your experience?') ->scale(1, 5) ->required(), Question::textarea('low_score_reason', 'What could we have done better?') ->when('experience', '<=', 3) ->required(), Question::boolean('recommend', 'Would you recommend us to a colleague?') ->required(), ]) );
2. Mount the Customer Widget
Drop the Blade component into your layout before </body>:
<x-simple-surveys::widget />
For Inertia.js or Livewire (wire:navigate), pass dynamic:
<x-simple-surveys::widget dynamic />
The widget renders nothing for guests (0 DB queries) or users without eligible surveys.
3. Open the Admin Results Dashboard
Authorize admin access via the viewSimpleSurveys Gate in AppServiceProvider::boot():
use Illuminate\Support\Facades\Gate; Gate::define('viewSimpleSurveys', fn ($user): bool => (bool) $user->is_admin);
Then visit /simple-surveys/admin to inspect funnel metrics, inline SVG charts (conversion funnel, time-series trends, rating histograms/NPS, boolean donuts), searchable & cross-filterable responses with a slide-over detail drawer, Light/Dark mode, CSV exports, lifecycle controls, and the live Appearance editor.
Dark Theme (bottom-right, Emerald) |
Centered Modal (center, Rose) |
|---|---|
![]() |
![]() |
Explore all themes, placements, and CSS token overrides in the Appearance & Styling gallery.
Documentation
| Guide | What You'll Learn |
|---|---|
| Defining Surveys | Survey & Question fluent API tables, all 8 question types, Question::nps() & scaleLabels(), php artisan make:survey & SurveyDefinition classes, conditional logic (->when), and DB syncing |
| Audience Targeting & Scheduling | Eloquent ->target(), ->targetUser(), route/path rules (onRoutes, onPaths), schedules, re-prompt cooldowns, and priority order |
| Customer Widget & SPA Mode | Component attributes (position, theme, icon, survey, nonce), Inertia/Livewire dynamic mode, CSP nonces, WCAG AA accessibility, and publishing Blade views |
| Appearance & Styling | --lss-* CSS custom properties, global vs per-survey overrides, style precedence, and the Admin Appearance tab |
| Headless / API-Only Setup | Sanctum/Passport Bearer & cookie auth, CORS, routes.throttle rate limiting, JSON endpoints (?survey=, ?url=), duration_ms, and a full React example |
| Admin Results Dashboard | Gate authorization, funnel metrics, End/Re-open/Reset controls, CSV exports, programmatic PHP results API (SimpleSurveys::results()), and simple-surveys:results CLI |
| Localization & Translations | Publishable widget chrome, lang/{locale}/simple-surveys.php scaffolding (simple-surveys:translations), and locale recording |
| Analytics, Events & Tracking | Browser CustomEvents (GA4/PostHog/Mixpanel), tracking cookies, resolveTrackingContext, and Laravel lifecycle events |
| Webhooks & Notifications | Signed lifecycle webhooks (HMAC-SHA256, queues/retries) and Mail/Slack/custom submission notifications |
| Configuration & Artisan Commands | Full config/simple-surveys.php reference, custom DB connection, rate limiting, GDPR privacy (forgetRespondent/anonymizeRespondent), publish tags, CLI commands, CSP nonces, UUID/ULID respondents, and Octane notes |
| Recipes & Walkthroughs | End-to-end walkthroughs for CSAT + Slack alerts, multi-language cohort tracking, Inertia/Livewire SPAs, multi-theme styling, and GDPR user deletion |
Testing & Quality
composer test
composer analyse
composer format:check
Changelog, Contributing & Security
- See CHANGELOG.md for release notes and version history.
- See CONTRIBUTING.md for local development setup and pull request guidelines.
- See SECURITY.md for responsible security vulnerability reporting.
License
The MIT License (MIT). Please see LICENSE.md for more information.




