File size: 1,306 Bytes
52d9fb0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | <?php
namespace App\Models;
use App\Constants\Status;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Reviewer extends Authenticatable
{
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
protected $casts = ['subcategories' => 'array'];
public function scopeActive($query)
{
return $query->where('status', Status::ENABLE);
}
public function subCategories()
{
return $this->belongsToMany(SubCategory::class);
}
public function products()
{
return $this->hasMany(Product::class, 'assigned_to');
}
public function approvedProducts()
{
return $this->hasMany(Product::class, 'approved_by');
}
public function statusBadge(): Attribute
{
return new Attribute(function () {
$html = '';
if ($this->status == Status::ENABLE) {
$html = '<span class="badge badge--success">' . trans('Active') . '</span>';
} else {
$html = '<span class="badge badge--danger">' . trans('Banned') . '</span>';
}
return $html;
});
}
}
|