60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Category extends Model
|
|
{
|
|
public const TYPE_MEDIA = 'media';
|
|
public const TYPE_PLAYLIST = 'playlist';
|
|
public const TYPE_BREATHING_TEMPLATE = 'breathing_template';
|
|
|
|
public const TYPES = [
|
|
self::TYPE_MEDIA,
|
|
self::TYPE_PLAYLIST,
|
|
self::TYPE_BREATHING_TEMPLATE,
|
|
];
|
|
|
|
protected $fillable = ['name', 'type', 'order', 'description', 'icon', 'is_deeplink_only'];
|
|
|
|
protected $casts = [
|
|
'order' => 'integer',
|
|
'is_deeplink_only' => 'boolean',
|
|
];
|
|
|
|
protected $appends = ['icon_url', 'deep_link'];
|
|
|
|
public function getIconUrlAttribute(): ?string
|
|
{
|
|
return $this->icon ? asset('storage/' . $this->icon) : null;
|
|
}
|
|
|
|
public function getDeepLinkAttribute(): ?string
|
|
{
|
|
$canonical = config('deeplinks.category_pattern');
|
|
|
|
if ($canonical) {
|
|
return rtrim(str_replace('{id}', $this->id, $canonical), '/');
|
|
}
|
|
|
|
return url('/category/' . $this->id);
|
|
}
|
|
|
|
public function questions()
|
|
{
|
|
return $this->hasMany(Question::class);
|
|
}
|
|
|
|
public function subcategories()
|
|
{
|
|
return $this->hasMany(SubCategory::class);
|
|
}
|
|
|
|
public function media()
|
|
{
|
|
return $this->belongsToMany(Media::class, 'category_media');
|
|
}
|
|
}
|
|
|