PHPackages                             matt-daneshvar/laravel-survey - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. matt-daneshvar/laravel-survey

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

matt-daneshvar/laravel-survey
=============================

Create surveys inside your Laravel app

v0.6.0(3mo ago)28780.8k↓56.3%66MITPHPPHP ^8.2CI passing

Since Aug 21Pushed 3mo ago7 watchersCompare

[ Source](https://github.com/matt-daneshvar/laravel-survey)[ Packagist](https://packagist.org/packages/matt-daneshvar/laravel-survey)[ RSS](/packages/matt-daneshvar-laravel-survey/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (10)Dependencies (10)Versions (15)Used By (0)

Laravel Survey
==============

[](#laravel-survey)

[![Tests](https://github.com/matt-daneshvar/laravel-survey/actions/workflows/tests.yml/badge.svg)](https://github.com/matt-daneshvar/laravel-survey/actions/workflows/tests.yml)[![GitHub](https://camo.githubusercontent.com/d77595d0ef55b49e4b8e99900ee8f5b45499f06d9e1916928e6e53c0a34be799/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6174742d64616e6573687661722f6c61726176656c2d737572766579)](https://camo.githubusercontent.com/d77595d0ef55b49e4b8e99900ee8f5b45499f06d9e1916928e6e53c0a34be799/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6174742d64616e6573687661722f6c61726176656c2d737572766579)

Create and manage surveys within your Laravel app.

[![Demo](https://private-user-images.githubusercontent.com/10030505/316346970-1fd79b4b-5058-4049-a369-8439b0431fe2.gif?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvb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yRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNjMwVDE3NDQwM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThlNDUzYjZmZjdlMDFkODFiNGM0Y2RiMzY2ZDBhYzcxZmU0NzA0NjU2MGVjZWNhZGI2YTkzNDUxMjNjOGZlZWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRmdpZiJ9.OZQQF2xY6xyB4PmFnq4WX7ZAfy00-0NIMIoA91x8dMM)

[This video](https://youtu.be/BA7tc-2rcWg) walks through installing this package and creating a basic survey.

Installation
------------

[](#installation)

Require the package using composer.

```
composer require matt-daneshvar/laravel-survey
```

Publish the package migrations.

```
php artisan vendor:publish --provider="MattDaneshvar\Survey\SurveyServiceProvider" --tag="migrations"
```

Run the migrations to create all the required tables.

```
php artisan migrate
```

Usage
-----

[](#usage)

### Creating a Survey

[](#creating-a-survey)

Creating a new `Survey` is easy! You can build your survey fluently just like how you create all your `Eloquent` models in your app.

```
$survey = Survey::create(['name' => 'Cat Population Survey']);

$survey->questions()->create([
     'content' => 'How many cats do you have?',
     'type' => 'number',
     'rules' => ['numeric', 'min:0']
 ]);

$survey->questions()->create([
    'content' => 'What\'s the name of your first cat',
]);

$survey->questions()->create([
    'content' => 'Would you want a new cat?',
    'type' => 'radio',
    'options' => ['Yes', 'Oui']
]);
```

See [the list of available question types](#question-types).

#### Creating Multiple Sections

[](#creating-multiple-sections)

You may also park your questions under multiple sections.

```
$survey = Survey::create(['name' => 'Cat Population Survey']);

$one = $survey->sections()->create(['name' => 'Part One']);

$one->questions()->create([
    'content' => 'How many cats do you have?',
    'type' => 'number',
    'rules' => ['numeric', 'min:0']
]);

$two = $survey->sections()->create(['name' => 'Part Two']);

$two->questions()->create([
    'content' => 'What\'s the name of your first cat?',
]);

$two->questions()->create([
    'content' => 'Would you want a new cat?',
    'type' => 'radio',
    'options' => ['Yes', 'Oui']
]);
```

### Creating an Entry

[](#creating-an-entry)

#### From an Array

[](#from-an-array)

The `Entry` model comes with a `fromArray` function.
This is especially useful when you're creating an entry from a form submission.

```
(new Entry())->for($survey)->fromArray([
    'q1' => 'Yes',
    'q2' => 5
])->push();
```

The answer array should be in the format of `q + question_id => answer`, thus becoming `'q1' => 'my answer'`.

#### By a Specific User

[](#by-a-specific-user)

You may fluently specify the participant using the `by()` function.

```
(new Entry())->for($survey)->by($user)->fromArray($answers)->push();
```

### Setting Constraints

[](#setting-constraints)

When creating your survey, you may set some constraints to be enforced every time a new `Entry` is being created.

#### Allowing Guest Entries

[](#allowing-guest-entries)

By default, `Entry` models require a `participant_id` when being created. If you wish to change this behaviour and accept guest entries, set the `accept-guest-entries` option on your `Survey` model.

```
Survey::create(['settings' => ['accept-guest-entries' => true]]);
```

#### Adjusting Entries Per Participant Limit

[](#adjusting-entries-per-participant-limit)

All `Survey` models default to accept only **1 entry** per unique participant. You may adjust the `limit-per-participant` option on your `Survey` model or set it to `-1` to remove this limit altogether.

```
Survey::create(['settings' => ['limit-per-participant' => 1]]);
```

*Note that this setting will be ignored if the `accept-guest-entries` option is activated.*

### Validation

[](#validation)

#### Defining Validation Rules

[](#defining-validation-rules)

Add in a `rules` attribute when you're creating your `Question` to specify the validation logic for the answers being received.

```
Question::create([
    'content' => 'How many cats do you have?',
    'rules' => ['numeric', 'min:0']
]);
```

*Note that as opposed to the survey constraints, the question validators are not automatically triggered during the entry creation process. To validate the answers, you should manually run the validation in your controller (see below)*

#### Validating Submissions

[](#validating-submissions)

Validate user's input against the entire rule set of your `Survey` using Laravel's built in validator.

```
class SurveyEntriesController extends Controller
{
    public function store(Request $request, Survey $survey)
    {
        $answers = $request->validate($survey->rules);

        (new Entry())->for($survey)->fromArray($answers)->push();
    }
}
```

### Views

[](#views)

This package comes with boilerplate Bootstrap 4.0 views to display the surveys and some basic question types. These views are meant to serve as examples, and may not be sufficient for your final use case. To display a survey in a card, include the `survey` partial in your views:

```
@include('survey::standard', ['survey' => $survey])
```

#### Question Types

[](#question-types)

These are the question types included out of the box:

- `text` - Accepting text answers
- `number` - Accepting numeric answers
- `radio` - Options presented as radio buttons, accepting 1 option for the answer
- `multiselect` - Options presented as checkboxes, accepting multiple options for the answer

#### Customizing the Views

[](#customizing-the-views)

To customize the boilerplate views shipped with this package run `package:publish` with the `views` tag.

```
php artisan vendor:publish --provider="MattDaneshvar\Survey\SurveyServiceProvider" --tag="views"
```

This will create a new `vendor/survey` directory where you can fully customize the survey views to your liking.

#### Creating New Question Types

[](#creating-new-question-types)

Once you publish the views that come with this package, you can add your own custom question types by implementing new templates for them.

To implement a new `custom-select` type, for example, you should implement a new template under:

```
/vendor/survey/questions/types/custom-select.blade.php

```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

60

—

FairBetter than 98% of packages

Maintenance80

Actively maintained with recent releases

Popularity52

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 82.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~200 days

Recently: every ~275 days

Total

13

Last Release

108d ago

PHP version history (7 changes)v0.1.0PHP ^7.2

v0.1.3PHP ^7.1

v0.1.4PHP ^7.3|^7.4|^8.0

v0.2.1PHP ^7.3|^7.4|^8.0|^8.1

v0.4.0PHP ^7.3|^7.4|^8.0|^8.1|^8.2|^8.3

v0.5.0PHP ^8.1

v0.6.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/4dd4c3943583b0db4572b8702f3ee8f85a3fa7ecf99401d5f1add6613821f031?d=identicon)[matt-daneshvar](/maintainers/matt-daneshvar)

---

Top Contributors

[![matt-daneshvar](https://avatars.githubusercontent.com/u/10030505?v=4)](https://github.com/matt-daneshvar "matt-daneshvar (58 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (3 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![mrchimp](https://avatars.githubusercontent.com/u/147373?v=4)](https://github.com/mrchimp "mrchimp (2 commits)")[![jorporte](https://avatars.githubusercontent.com/u/48680228?v=4)](https://github.com/jorporte "jorporte (1 commits)")[![YutaInouePH](https://avatars.githubusercontent.com/u/58018461?v=4)](https://github.com/YutaInouePH "YutaInouePH (1 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (1 commits)")[![stojankukrika](https://avatars.githubusercontent.com/u/10199584?v=4)](https://github.com/stojankukrika "stojankukrika (1 commits)")[![walid-mashal](https://avatars.githubusercontent.com/u/30696582?v=4)](https://github.com/walid-mashal "walid-mashal (1 commits)")

---

Tags

laravelpollsurveylaravelsurvey

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/matt-daneshvar-laravel-survey/health.svg)

```
[![Health](https://phpackages.com/badges/matt-daneshvar-laravel-survey/health.svg)](https://phpackages.com/packages/matt-daneshvar-laravel-survey)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58171.8k14](/packages/api-platform-laravel)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)[offload-project/laravel-toggle

A simple and flexible feature toggle (feature flag) package for Laravel

251.6k](/packages/offload-project-laravel-toggle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
