Looking to hire Laravel developers? Try LaraJobs

laravel-simple-surveys maintained by danielcristeaa

Description
A lightweight, code-first Laravel package for running targeted in-app surveys with a drop-in Blade widget and protected results dashboard.
Author
Daniel Cristea
Last update
2026/12/02 12:55 (dev-main)
License
Downloads
1

Comments
comments powered by Disqus

Laravel Simple Surveys

Tests Latest Version on Packagist Total Downloads PHP Version License

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.

Customer survey widget interactive demo


Features

  • Code-first fluent API: Define surveys, 8 input types (plus Question::nps() & rating scaleLabels()), conditional follow-ups (->when(...)), and scaffold SurveyDefinition classes via php 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/Livewire dynamic SPA 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.php scaffolding (simple-surveys:translations), and automatic respondent locale recording.
  • 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, and forgetRespondent() / 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 DB connection support, and PHPStan Level 8+.

Admin Results Dashboard overview


Requirements

  • PHP 8.2+
  • Laravel 11.x, 12.x, or 13.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.

Admin Appearance Editor with live preview

Dark Theme (bottom-right, Emerald) Centered Modal (center, Rose)
Dark Emerald preset Centered Modal Rose preset

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.