Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nelkasovic committed Sep 18, 2021
1 parent 5cc23fe commit 4d9f3c3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
27 changes: 19 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Laravel Survey
Create and manage surveys within your Laravel app.
I decided to fork this one `https://github.com/matt-daneshvar/laravel-survey` and modify to fit project needs.

## Installation
Require the package using composer.
Expand All @@ -24,7 +25,9 @@ php artisan migrate
Creating a new `Survey` is easy! You can build your survey fluently just like
how you create all your `Eloquent` models in your app.
```php
$survey = Survey::create(['name' => 'Cat Population Survey']);
$survey = SurveyFactory::create(['name' => 'Cat Population Survey']);

$survey->save();

$survey->questions()->create([
'content' => 'How many cats do you have?',
Expand All @@ -46,7 +49,9 @@ $survey->questions()->create([
#### Creating Multiple Sections
You may also park your questions under multiple sections.
```php
$survey = Survey::create(['name' => 'Cat Population Survey']);
$survey = SurveyFactory::create(['name' => 'Cat Population Survey']);

$survey->save();

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

Expand Down Expand Up @@ -75,7 +80,9 @@ $two->questions()->create([
The `Entry` model comes with a `fromArray` function.
This is especially useful when you're creating an entry from a form submission.
```php
(new Entry)->for($survey)->fromArray([
$entry = EntryFactory::create();

$entry->for($survey)->fromArray([
'q1' => 'Yes',
'q2' => 5
])->push();
Expand All @@ -84,7 +91,9 @@ This is especially useful when you're creating an entry from a form submission.
#### By a Specific User
You may fluently specify the participant using the `by()` function.
```php
(new Entry)->for($survey)->by($user)->fromArray($answers)->push();
$entry = EntryFactory::create();

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

### Setting Constraints
Expand All @@ -96,15 +105,15 @@ 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.
```php
Survey::create(['settings' => ['accept-guest-entries' => true]]);
SurveyFactory::create(['settings' => ['accept-guest-entries' => true]]);
```

#### 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.
```php
Survey::create(['settings' => ['limit-per-participant' => 1]]);
SurveyFactory::create(['settings' => ['limit-per-participant' => 1]]);
```
*Note that this setting will be ignored if the `accept-guest-entries` option is activated.*

Expand All @@ -114,7 +123,7 @@ Survey::create(['settings' => ['limit-per-participant' => 1]]);
Add in a `rules` attribute when you're creating your `Question` to specify the validation logic
for the answers being received.
```php
Question::create([
QuestionFactory::create([
'content' => 'How many cats do you have?',
'rules' => ['numeric', 'min:0']
]);
Expand All @@ -132,7 +141,9 @@ class SurveyEntriesController extends Controller
{
$answers = $this->validate($request, $survey);

(new Entry)->for($survey)->fromArray($answers)->push();
$entry = EntryFactory::create();

$entry->for($survey)->fromArray($answers)->push();
}
}
```
Expand Down
22 changes: 22 additions & 0 deletions resources/views/questions/types/checkbox.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@component('survey::questions.base', compact('question'))
@foreach($question->options as $option)
<div class="custom-control custom-radio">
<input type="radio"
name="{{ $question->key }}"
id="{{ $question->key . '-' . Str::slug($option) }}"
value="{{ $option }}"
class="custom-control-input"
{{ ($value ?? old($question->key)) == $option ? 'checked' : '' }}
{{ ($disabled ?? false) ? 'disabled' : '' }}
>
<label class="custom-control-label"
for="{{ $question->key . '-' . Str::slug($option) }}">{{ $option }}
@if($includeResults ?? false)
<span class="text-success">
({{ number_format((new \Wimando\Survey\Utilities\Summary($question))->similarAnswersRatio($option) * 100, 2) }}%)
</span>
@endif
</label>
</div>
@endforeach
@endcomponent
2 changes: 1 addition & 1 deletion resources/views/questions/types/radio.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@component('survey::questions.base', compact('question'))
@foreach($question->options as $option)
<div class="custom-control custom-radio">
<input type="radio"
<input type="checkbox"
name="{{ $question->key }}"
id="{{ $question->key . '-' . Str::slug($option) }}"
value="{{ $option }}"
Expand Down

0 comments on commit 4d9f3c3

Please sign in to comment.