added evaluationables relations to models

pull/49/head
A1Gard 3 months ago
parent 9ceeb619a6
commit 44b499d082

@ -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();
}
}

@ -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();
}
}

@ -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();
}
}

@ -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();
}
}

@ -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();
}
}

@ -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();
}
}

@ -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();
}
}

@ -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();
}
}

Loading…
Cancel
Save