67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class TaskCollection extends Model
|
|
{
|
|
protected $table = 'task_collections';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'description',
|
|
];
|
|
|
|
protected $casts = [
|
|
'name' => 'array',
|
|
'description' => 'array',
|
|
];
|
|
|
|
/**
|
|
* Tasks in this collection
|
|
*/
|
|
public function tasks(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
Task::class,
|
|
'task_collection_task',
|
|
'task_collection_id',
|
|
'task_id'
|
|
)->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* Events that use this collection
|
|
*/
|
|
public function events(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
Event::class,
|
|
'event_task_collection',
|
|
'task_collection_id',
|
|
'event_id'
|
|
)->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* Get the localized name for the current locale
|
|
*/
|
|
public function getLocalizedNameAttribute(): string
|
|
{
|
|
$locale = app()->getLocale();
|
|
return $this->name[$locale] ?? $this->name['de'] ?? 'Unnamed Collection';
|
|
}
|
|
|
|
/**
|
|
* Get the localized description for the current locale
|
|
*/
|
|
public function getLocalizedDescriptionAttribute(): ?string
|
|
{
|
|
if (!$this->description) return null;
|
|
|
|
$locale = app()->getLocale();
|
|
return $this->description[$locale] ?? $this->description['de'] ?? null;
|
|
}
|
|
} |