File size: 1,663 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 58 59 60 61 62 63 64 65 66 67 68 | <?php
namespace App\Models;
use App\Constants\Status;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class OrderItem extends Model
{
protected $guarded = ['id'];
public function order()
{
return $this->belongsTo(Order::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
public function scopePaid($query)
{
return $query->whereHas('order', function ($query) {
$query->where('payment_status', 1);
});
}
public function scopeRefunded($query)
{
return $query->where('is_refunded', Status::YES);
}
public function buyer()
{
return $this->belongsTo(User::class, 'user_id');
}
public function licenseBadge(): Attribute
{
return new Attribute(function () {
$html = '';
if ($this->license == Status::PERSONAL_LICENSE) {
$html = '<span class="badge badge--primary">' . trans('Personal') . '</span>';
} else {
$html = '<span class="badge badge--success">' . trans('Commercial') . '</span>';
}
return $html;
});
}
public function refundedBadge(): Attribute
{
return new Attribute(function () {
$html = '';
if ($this->is_refunded == Status::YES) {
$html = '<span class="badge badge--danger">' . trans('Yes') . '</span>';
} else {
$html = '<span class="badge badge--success">' . trans('No') . '</span>';
}
return $html;
});
}
}
|