Changeset View
Changeset View
Standalone View
Standalone View
src/app/Sku.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use Illuminate\Database\Eloquent\Model; | |||||
use Spatie\Translatable\HasTranslations; | |||||
use App\Traits\BelongsToTenantTrait; | use App\Traits\BelongsToTenantTrait; | ||||
use App\Traits\UuidStrKeyTrait; | use App\Traits\UuidStrKeyTrait; | ||||
use Illuminate\Database\Eloquent\Model; | |||||
use Spatie\Translatable\HasTranslations; | |||||
/** | /** | ||||
* The eloquent definition of a Stock Keeping Unit (SKU). | * The eloquent definition of a Stock Keeping Unit (SKU). | ||||
* | * | ||||
* @property bool $active | * @property bool $active | ||||
* @property int $cost | * @property int $cost | ||||
* @property string $description | * @property string $description | ||||
* @property int $fee The fee that the tenant pays to us | * @property int $fee The fee that the tenant pays to us | ||||
* @property string $handler_class | * @property string $handler_class | ||||
* @property string $id | * @property string $id | ||||
* @property string $name | * @property string $name | ||||
* @property string $period | * @property string $period | ||||
* @property ?int $tenant_id | * @property ?int $tenant_id | ||||
* @property string $title | * @property string $title | ||||
* @property int $units_free | * @property int $units_free | ||||
*/ | */ | ||||
class Sku extends Model | class Sku extends Model | ||||
{ | { | ||||
use BelongsToTenantTrait; | use BelongsToTenantTrait; | ||||
use HasTranslations; | use HasTranslations; | ||||
use UuidStrKeyTrait; | use UuidStrKeyTrait; | ||||
/** @var array<string, string> The attributes that should be cast */ | |||||
protected $casts = [ | protected $casts = [ | ||||
'units_free' => 'integer' | 'units_free' => 'integer' | ||||
]; | ]; | ||||
/** @var array<int, string> The attributes that are mass assignable */ | |||||
protected $fillable = [ | protected $fillable = [ | ||||
'active', | 'active', | ||||
'cost', | 'cost', | ||||
'description', | 'description', | ||||
'fee', | 'fee', | ||||
'handler_class', | 'handler_class', | ||||
'name', | 'name', | ||||
// persist for annual domain registration | // persist for annual domain registration | ||||
'period', | 'period', | ||||
'title', | 'title', | ||||
'units_free', | 'units_free', | ||||
]; | ]; | ||||
/** @var array Translatable properties */ | /** @var array<int, string> Translatable properties */ | ||||
public $translatable = [ | public $translatable = [ | ||||
'name', | 'name', | ||||
'description', | 'description', | ||||
]; | ]; | ||||
/** | /** | ||||
* List the entitlements that consume this SKU. | * List the entitlements that consume this SKU. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function entitlements() | public function entitlements() | ||||
{ | { | ||||
return $this->hasMany('App\Entitlement'); | return $this->hasMany(Entitlement::class); | ||||
} | } | ||||
/** | /** | ||||
* List of packages that use this SKU. | * List of packages that use this SKU. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
*/ | */ | ||||
public function packages() | public function packages() | ||||
{ | { | ||||
return $this->belongsToMany( | return $this->belongsToMany(Package::class, 'package_skus') | ||||
'App\Package', | ->using(PackageSku::class) | ||||
'package_skus' | ->withPivot(['cost', 'qty']); | ||||
)->using('App\PackageSku')->withPivot(['cost', 'qty']); | |||||
} | } | ||||
} | } |