PHPackages                             chapdel/survey-for-laravel - 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. chapdel/survey-for-laravel

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

chapdel/survey-for-laravel
==========================

Create surveys inside your Laravel app

1.0.0(3y ago)17MITPHPPHP ^7.3|^7.4|^8.0|^8.1|^8.2

Since Apr 4Pushed 3y agoCompare

[ Source](https://github.com/chapdel/laravel-survey)[ Packagist](https://packagist.org/packages/chapdel/survey-for-laravel)[ RSS](/packages/chapdel-survey-for-laravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

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

[](#laravel-survey)

[![Build Status](https://camo.githubusercontent.com/74ac2843cfb72b7ad0ab031234d43ad9ca7a27a339ca30a6d26f55a4a9b6d272/68747470733a2f2f7472617669732d63692e6f72672f6d6174742d64616e6573687661722f6c61726176656c2d7375727665792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/matt-daneshvar/laravel-survey)[![GitHub](https://camo.githubusercontent.com/d77595d0ef55b49e4b8e99900ee8f5b45499f06d9e1916928e6e53c0a34be799/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6174742d64616e6573687661722f6c61726176656c2d737572766579)](https://camo.githubusercontent.com/d77595d0ef55b49e4b8e99900ee8f5b45499f06d9e1916928e6e53c0a34be799/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6174742d64616e6573687661722f6c61726176656c2d737572766579)

Create and manage surveys within your Laravel app. [![alt text](https://raw.githubusercontent.com/matt-daneshvar/laravel-survey/master/demo.gif)](https://raw.githubusercontent.com/matt-daneshvar/laravel-survey/master/demo.gif)

[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 chapdel/survey-for-laravel
```

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();
```

#### 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(Survey $survey, Request $request)
    {
        $answers = $this->validate($request, $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
- `mutliselect` - 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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.6% 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

Unknown

Total

1

Last Release

1134d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20987014?v=4)[Chapdel KAMGA](/maintainers/chapdel)[@chapdel](https://github.com/chapdel)

---

Top Contributors

[![matt-daneshvar](https://avatars.githubusercontent.com/u/10030505?v=4)](https://github.com/matt-daneshvar "matt-daneshvar (44 commits)")[![mrchimp](https://avatars.githubusercontent.com/u/147373?v=4)](https://github.com/mrchimp "mrchimp (2 commits)")[![chapdel](https://avatars.githubusercontent.com/u/20987014?v=4)](https://github.com/chapdel "chapdel (2 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (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)")[![jorporte](https://avatars.githubusercontent.com/u/48680228?v=4)](https://github.com/jorporte "jorporte (1 commits)")[![stojankukrika](https://avatars.githubusercontent.com/u/10199584?v=4)](https://github.com/stojankukrika "stojankukrika (1 commits)")

---

Tags

laravelsurvey

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chapdel-survey-for-laravel/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[matt-daneshvar/laravel-survey

Create surveys inside your Laravel app

28770.3k](/packages/matt-daneshvar-laravel-survey)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)[tapp/filament-form-builder

User facing form builder using Filament components

131.2k1](/packages/tapp-filament-form-builder)

PHPackages © 2026

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