90 lines
1.9 KiB
PHP
90 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class PreregistrationPage extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'slug',
|
|
'user_id',
|
|
'title',
|
|
'heading',
|
|
'intro_text',
|
|
'thank_you_message',
|
|
'expired_message',
|
|
'ticketshop_url',
|
|
'start_date',
|
|
'end_date',
|
|
'phone_enabled',
|
|
'background_image',
|
|
'logo_image',
|
|
'is_active',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'start_date' => 'datetime',
|
|
'end_date' => 'datetime',
|
|
'phone_enabled' => 'boolean',
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Route model binding uses 'slug' instead of 'id'.
|
|
*/
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'slug';
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function subscribers(): HasMany
|
|
{
|
|
return $this->hasMany(Subscriber::class);
|
|
}
|
|
|
|
public function mailwizzConfig(): HasOne
|
|
{
|
|
return $this->hasOne(MailwizzConfig::class);
|
|
}
|
|
|
|
public function isBeforeStart(): bool
|
|
{
|
|
return Carbon::now()->lt($this->start_date);
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
$now = Carbon::now();
|
|
return $now->gte($this->start_date) && $now->lte($this->end_date);
|
|
}
|
|
|
|
public function isExpired(): bool
|
|
{
|
|
return Carbon::now()->gt($this->end_date);
|
|
}
|
|
|
|
public function scopeActive(Builder $query): Builder
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
}
|