Page MenuHomePhorge

PlanPackage.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

PlanPackage.php

<?php
namespace App;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot;
/**
* Link Packages to Plans.
*
* @property int $discount_qty
* @property int $discount_rate
* @property string $plan_id
* @property string $package_id
* @property int $qty
* @property int $qty_max
* @property int $qty_min
* @property Package $package
* @property Plan $plan
*/
class PlanPackage extends Pivot
{
/** @var list<string> The attributes that are mass assignable */
protected $fillable = [
'plan_id',
'package_id',
'qty',
'qty_max',
'qty_min',
'discount_qty',
'discount_rate',
];
/** @var array<string, string> The attributes that should be cast */
protected $casts = [
'qty' => 'integer',
'qty_max' => 'integer',
'qty_min' => 'integer',
'discount_qty' => 'integer',
'discount_rate' => 'integer',
];
/**
* Calculate the costs for this package.
*
* @return int The costs in cents
*/
public function cost()
{
$costs = 0;
// TODO: consider discount_qty/discount_rate here?
if ($this->qty_min > 0) {
$costs += $this->package->cost() * $this->qty_min;
} elseif ($this->qty > 0) {
$costs += $this->package->cost() * $this->qty;
}
return $costs;
}
/**
* The package in this relation.
*
* @return BelongsTo<Package, $this>
*/
public function package()
{
return $this->belongsTo(Package::class);
}
/**
* The plan in this relation.
*
* @return BelongsTo<Plan, $this>
*/
public function plan()
{
return $this->belongsTo(Plan::class);
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Apr 4, 5:07 AM (1 d, 22 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4f/a2/46bb3687b39cf46fb6a9b3c1232a
Default Alt Text
PlanPackage.php (1 KB)

Event Timeline