Files
wticreatorstudio/Modules/WTIALaCarte/Entities/Alacarte.php
T

56 lines
1.6 KiB
PHP

<?php
namespace Modules\WTIALaCarte\Entities;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\WTIJobBoard\Entities\JobRequestCategory;
class Alacarte extends Model
{
use SoftDeletes;
protected $table = "alacarte";
protected $guarded = ["id"];
protected $dates = ['deleted_at'];
protected $casts = [
'price' => 'float',
'stock' => 'integer',
'status' => 'boolean',
];
protected $appends = [
'image_url',
'final_price'
];
public function category() {
return $this->belongsTo(JobRequestCategory::class, 'category_id', 'id');
}
public function getImageUrlAttribute()
{
return "/public/storage/{$this->image}";
}
public function getFinalPriceAttribute()
{
$currentSubscription = auth()->user()->currentSubscription();
if($currentSubscription) {
if($currentSubscription->status == 'active'){
return ($this->price - ($this->price * ($currentSubscription->planPrice->plan->discount / 100) ));
}
if($currentSubscription->status == 'cancelled'){
$subscription_expired = $currentSubscription->expired_at != null ? \Carbon\Carbon::now()->gt(\Carbon\Carbon::parse($currentSubscription->expired_at)) : true;
if(!$subscription_expired) {
return ($this->price - ($this->price * ($currentSubscription->planPrice->plan->discount / 100) ));
}
}
}
return $this->price;
}
}