feat(packages): implement package-based business model
This commit is contained in:
86
app/Models/Package.php
Normal file
86
app/Models/Package.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Package extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'type',
|
||||
'price',
|
||||
'max_photos',
|
||||
'max_guests',
|
||||
'gallery_days',
|
||||
'max_tasks',
|
||||
'watermark_allowed',
|
||||
'branding_allowed',
|
||||
'max_events_per_year',
|
||||
'expires_after',
|
||||
'features',
|
||||
'description',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'price' => 'decimal:2',
|
||||
'max_photos' => 'integer',
|
||||
'max_guests' => 'integer',
|
||||
'gallery_days' => 'integer',
|
||||
'max_tasks' => 'integer',
|
||||
'max_events_per_year' => 'integer',
|
||||
'expires_after' => 'datetime',
|
||||
'watermark_allowed' => 'boolean',
|
||||
'branding_allowed' => 'boolean',
|
||||
'features' => 'array',
|
||||
];
|
||||
|
||||
protected function features(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value) => $value ? json_decode($value, true) : [],
|
||||
set: fn (array $value) => json_encode($value),
|
||||
);
|
||||
}
|
||||
|
||||
public function eventPackages(): HasMany
|
||||
{
|
||||
return $this->hasMany(EventPackage::class);
|
||||
}
|
||||
|
||||
public function tenantPackages(): HasMany
|
||||
{
|
||||
return $this->hasMany(TenantPackage::class);
|
||||
}
|
||||
|
||||
public function packagePurchases(): HasMany
|
||||
{
|
||||
return $this->hasMany(PackagePurchase::class);
|
||||
}
|
||||
|
||||
public function isEndcustomer(): bool
|
||||
{
|
||||
return $this->type === 'endcustomer';
|
||||
}
|
||||
|
||||
public function isReseller(): bool
|
||||
{
|
||||
return $this->type === 'reseller';
|
||||
}
|
||||
|
||||
public function getLimitsAttribute(): array
|
||||
{
|
||||
return [
|
||||
'max_photos' => $this->max_photos,
|
||||
'max_guests' => $this->max_guests,
|
||||
'gallery_days' => $this->gallery_days,
|
||||
'max_tasks' => $this->max_tasks,
|
||||
'max_events_per_year' => $this->max_events_per_year,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user