Skip to content

Commit

Permalink
store user request info
Browse files Browse the repository at this point in the history
  • Loading branch information
mydnic committed Nov 12, 2018
1 parent b90a533 commit 57255b6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion public/css/kustomer.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/kustomer.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/kustomer.js": "/js/kustomer.js?id=7e7e4a894bbfd0b85b69",
"/css/kustomer.css": "/css/kustomer.css?id=f4eb94ff7665395ad49e"
"/js/kustomer.js": "/js/kustomer.js?id=cd3705d0cd5d9e656861",
"/css/kustomer.css": "/css/kustomer.css?id=77fcb16776316cfcfb3e"
}
6 changes: 5 additions & 1 deletion resources/js/components/Partials/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export default {
this.isLoading = true;
axios.post('/kustomer-api/feedback', {
type: this.feedback.type,
message: this.message
message: this.message,
viewport: {
width: Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
height: Math.max(document.documentElement.clientHeight, window.innerHeight || 0),
}
})
.then(response => {
this.isLoading = false;
Expand Down
1 change: 1 addition & 0 deletions src/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class Feedback extends Model

protected $casts = [
'reviewed' => 'boolean',
'user_info' => 'array'
];
}
18 changes: 15 additions & 3 deletions src/Http/Controllers/FeedbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function store(Request $request)
{
$data = $this->validates($request);

$feedback = $this->storeFeedback($data);
$feedback = $this->storeFeedback($data, $request);

$this->dispatchEvent($feedback);

Expand All @@ -30,20 +30,32 @@ private function validates(Request $request)
'required', Rule::in(array_keys(config('kustomer.feedbacks'))),
],
'message' => 'required',
'viewport' => 'array',
]);
}

private function storeFeedback($data)
private function storeFeedback($data, Request $request)
{
$feedback = new Feedback;
$feedback->type = $data['type'];
$feedback->message = $data['message'];
$feedback->user_info = $this->gatherUserInfo($request);
$feedback->save();

return $feedback;
}

public function dispatchEvent(Feedback $feedback)
private function gatherUserInfo(Request $request)
{
return [
'url' => $request->server('HTTP_REFERER'),
'language' => $request->getPreferredLanguage(),
'agent' => $request->server('HTTP_USER_AGENT'),
'viewport' => $request->viewport
];
}

private function dispatchEvent(Feedback $feedback)
{
event(new NewFeedback($feedback));
}
Expand Down

0 comments on commit 57255b6

Please sign in to comment.