You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB
PHTML

<?php
namespace App\Models;
1 year ago
use Illuminate\Database\Eloquent\Casts\Attribute;
class SaleItem extends Model
{
protected $fillable = [
'sale_id',
'entity_type',
'entity_id',
'price',
'quantity',
'additional_info_json',
];
1 year ago
protected $appends = [
'share_word',
];
public function related()
{
return $this->belongsTo($this->entity_type, 'entity_id');
}
public function voucher()
{
return $this->belongsTo(Voucher::class, 'entity_id');
}
1 year ago
1 year ago
public function sale()
{
return $this->belongsTo(Sale::class, 'sale_id');
}
1 year ago
public function shareWord(): Attribute
{
return Attribute::make(get: function () {
$item = json_decode($this->additional_info_json);
$string = "Hai, aku baru beli voucher {$item->voucher->location->name} di " . route('home.index');
$string .= " voucher {$item->voucher->display_quota} buat {$item->voucher->display_expired}
1 year ago
Username : {$item->voucher->username}
Password : {$item->voucher->password}
1 year ago
";
$string .= "Cuman Rp" . number_format($this->price, '0', ',', '.') . " aja, ";
if ($item->voucher->discount > 0) {
$string .= "lagi ada discount {$item->voucher->discount}% loh.
1 year ago
";
}
$string .= "dapatkat penawaran voucher lainnya di " . route('home.index');
return $string;
});
}
}