SurveyJS Server Integration · PHP / Laravel II · See results in a dashboard
You work in a private copy of the demo database, kept until it has been unused for 24 hours.

II

See results in a dashboard

You need this: When people need to see answers, not just store them.

SurveyJS Dashboard runs in the browser. Your backend returns the stored responses; the client hands them to the Dashboard together with the definition, and it picks a chart per question type. One endpoint returns the responses for a form. For large volumes, filter by date or paginate on the server instead of sending everything to the browser.

This step on the Server Integration page Source on GitHub Commercial client licence: without SURVEYJS_LICENSE_KEY the component shows a licence banner

Try this

  1. About 200 seeded feedback responses, spread over the last 90 days, render in the Dashboard.
  2. Change From: a new GET /api/responses?formId=feedback&from=… appears in Requests, and "What the server stored" shows how many responses the server has since that date.
  3. The definition comes from GET /api/forms/feedback, the I.2 endpoint; the Dashboard reads its .definition.

Code that just ran

These regions are read from the files that served this page, the same lines the Server Integration page shows.

Client · shared/client/dashboard.js · sjs:II.client View on GitHub
import { Model } from "survey-core";
import { VisualizationPanel } from "survey-analytics";

async function showDashboard(from) {
  const { definition } = await fetch("/api/forms/feedback").then(r => r.json());   // .definition: the I.2 endpoint
  const responses = await fetch(`/api/responses?formId=feedback&from=${from}`).then(r => r.json());

  const survey = new Model(definition);
  const dashboard = new VisualizationPanel(survey.getAllQuestions(), responses);
  dashboard.render(document.getElementById("dashboard"));
  return dashboard;
}
Server · routes/examples/dashboard.php · sjs:II.server View on GitHub
// GET /api/responses?formId=&from=&limit=&offset= — the stored answers as an array
Route::get('/api/responses', function (Request $request) {
    $documents = DB::table('responses')
        ->where('form_id', $request->query('formId'))
        ->where('created_at', '>=', $request->query('from', '1970-01-01'))   // ISO-8601 UTC strings compare as dates
        ->orderBy('created_at')
        ->limit(min(max((int) $request->query('limit', 500), 1), 5000))       // filter or page on the server for large volumes
        ->offset(max((int) $request->query('offset', 0), 0))
        ->pluck('data');

    return response('['.$documents->implode(',').']')                        // documents as stored, not re-encoded
        ->header('Content-Type', 'application/json');
});

Definition: shared/definitions/dashboard.json