Skip to content

Beautiful Open-Source Form Builder

Form views count compatible with mysql (#58)

Brian Davis771e3b01c530
diff --git a/app/Models/Forms/Form.php b/app/Models/Forms/Form.php
index 2d8195b68..e0253a5f6 100644
--- a/app/Models/Forms/Form.php
+++ b/app/Models/Forms/Form.php
@@ -137,8 +137,13 @@ class Form extends Model
public function getViewsCountAttribute()
{
- return $this->views()->count() +
+ if(env('DB_CONNECTION') == 'pgsql') {
+ return $this->views()->count() +
$this->statistics()->sum(DB::raw("cast(data->>'views' as integer)"));
+ } elseif(env('DB_CONNECTION') == 'mysql') {
+ return $this->views()->count() +
+ $this->statistics()->sum(DB::raw("json_extract(data, '$.views')")); // code to
+ }
}
public function setDescriptionAttribute($value)