Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,18 @@ $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([
(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
You may fluently specify the participant using the `by()` function.
```php
(new Entry)->for($survey)->by($user)->fromArray($answers)->push();
(new Entry())->for($survey)->by($user)->fromArray($answers)->push();
```

### Setting Constraints
Expand Down Expand Up @@ -137,11 +139,11 @@ Validate user's input against the entire rule set of your `Survey` using Laravel
```php
class SurveyEntriesController extends Controller
{
public function store(Survey $survey, Request $request)
public function store(Request $request, Survey $survey)
{
$answers = $request->validate($request, $survey->rules);
$answers = $request->validate($survey->rules);

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