Initial commit
This commit is contained in:
69
api/app/Models/Event.php
Normal file
69
api/app/Models/Event.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
protected $hidden = ['upload_password'];
|
||||
|
||||
protected $appends = ['has_password'];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
'description',
|
||||
'slug',
|
||||
'google_drive_folder_id',
|
||||
'google_drive_folder_name',
|
||||
'is_active',
|
||||
'upload_start_at',
|
||||
'upload_end_at',
|
||||
'max_file_size_mb',
|
||||
'allowed_extensions',
|
||||
'upload_password',
|
||||
'require_password',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'upload_start_at' => 'datetime',
|
||||
'upload_end_at' => 'datetime',
|
||||
'is_active' => 'boolean',
|
||||
'require_password' => 'boolean',
|
||||
'allowed_extensions' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function getAllowedExtensionsAttribute($value): array
|
||||
{
|
||||
$decoded = $value ? json_decode($value, true) : null;
|
||||
|
||||
return is_array($decoded) ? $decoded : ['mp4', 'mov', 'avi', 'mkv', 'webm'];
|
||||
}
|
||||
|
||||
public function getHasPasswordAttribute(): bool
|
||||
{
|
||||
return ! empty($this->attributes['upload_password'] ?? null);
|
||||
}
|
||||
|
||||
public function setUploadPasswordAttribute(?string $value): void
|
||||
{
|
||||
$this->attributes['upload_password'] = $value ? Hash::make($value) : null;
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function uploads(): HasMany
|
||||
{
|
||||
return $this->hasMany(Upload::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user