diff --git a/app/Models/Category.php b/app/Models/Category.php index df8abf0..2f5f5c0 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -95,4 +95,17 @@ class Category extends Model ]); } + public function evaluations(){ + + return Evaluation::where(function ($query) { + $query->whereNull('evaluationable_type') + ->whereNull('evaluationable_id'); + })->orWhere(function ($query) { + $query->where('evaluationable_type', Category::class) + ->whereNull('evaluationable_id'); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Category::class) + ->where('evaluationable_id',$this->id); + })->get(); + } } diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 1fed8c2..d52d5ba 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -54,4 +54,19 @@ class Customer extends Authenticatable } + public function evaluations(){ + + return Evaluation::where(function ($query) { + $query->whereNull('evaluationable_type') + ->whereNull('evaluationable_id'); + })->orWhere(function ($query) { + $query->where('evaluationable_type', Customer::class) + ->whereNull('evaluationable_id'); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Customer::class) + ->where('evaluationable_id',$this->id); + })->get(); + } + + } diff --git a/app/Models/Group.php b/app/Models/Group.php index ceacf03..9721603 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -92,4 +92,18 @@ class Group extends Model return $this->posts()->where('status', 1) ->orderBy($order, $dir)->limit($limit)->get(['title', 'slug', 'icon']); } + + public function evaluations(){ + + return Evaluation::where(function ($query) { + $query->whereNull('evaluationable_type') + ->whereNull('evaluationable_id'); + })->orWhere(function ($query) { + $query->where('evaluationable_type', Group::class) + ->whereNull('evaluationable_id'); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Group::class) + ->where('evaluationable_id',$this->id); + })->get(); + } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 3add0a8..62514ca 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -166,4 +166,17 @@ class Invoice extends Model return $this->belongsTo(Address::class); } + public function evaluations(){ + + return Evaluation::where(function ($query) { + $query->whereNull('evaluationable_type') + ->whereNull('evaluationable_id'); + })->orWhere(function ($query) { + $query->where('evaluationable_type', Invoice::class) + ->whereNull('evaluationable_id'); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Invoice::class) + ->where('evaluationable_id',$this->id); + })->get(); + } } diff --git a/app/Models/Post.php b/app/Models/Post.php index d646db6..6823bb0 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -206,4 +206,22 @@ RESULT; list($toc, $modifiedHtml) = generateTOC($this->body); return $modifiedHtml; } + + + public function evaluations(){ + + return Evaluation::where(function ($query) { + $query->whereNull('evaluationable_type') + ->whereNull('evaluationable_id'); + })->orWhere(function ($query) { + $query->where('evaluationable_type', Post::class) + ->whereNull('evaluationable_id'); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Post::class) + ->where('evaluationable_id',$this->id); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Group::class) + ->where('evaluationable_id',$this->group_id); + })->get(); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 47832ad..d6ffcf3 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -440,4 +440,22 @@ RESULT; return implode(',', $this->tags()->pluck('name')->toArray()); } } + + + public function evaluations(){ + + return Evaluation::where(function ($query) { + $query->whereNull('evaluationable_type') + ->whereNull('evaluationable_id'); + })->orWhere(function ($query) { + $query->where('evaluationable_type', Product::class) + ->whereNull('evaluationable_id'); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Product::class) + ->where('evaluationable_id',$this->id); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Category::class) + ->where('evaluationable_id',$this->category_id); + })->get(); + } } diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index e68be4e..646ffc2 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -24,4 +24,19 @@ class Ticket extends Model public function subTickets(){ return $this->hasMany(Ticket::class,'parent_id','id')->orderBy('id'); } + + + public function evaluations(){ + + return Evaluation::where(function ($query) { + $query->whereNull('evaluationable_type') + ->whereNull('evaluationable_id'); + })->orWhere(function ($query) { + $query->where('evaluationable_type', Ticket::class) + ->whereNull('evaluationable_id'); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', Ticket::class) + ->where('evaluationable_id',$this->id); + })->get(); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 854c514..44238e7 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -151,4 +151,19 @@ class User extends Authenticatable } return $this->accesses()->where('route', $route)->count() > 0; } + + + public function evaluations(){ + + return Evaluation::where(function ($query) { + $query->whereNull('evaluationable_type') + ->whereNull('evaluationable_id'); + })->orWhere(function ($query) { + $query->where('evaluationable_type', User::class) + ->whereNull('evaluationable_id'); + })->orWhere(function ($query ) { + $query->where('evaluationable_type', User::class) + ->where('evaluationable_id',$this->id); + })->get(); + } }