feat: deep link added
This commit is contained in:
+14
-2
@@ -16,19 +16,31 @@ class Category extends Model
|
||||
self::TYPE_BREATHING_TEMPLATE,
|
||||
];
|
||||
|
||||
protected $fillable = ['name', 'type', 'order', 'description', 'icon'];
|
||||
protected $fillable = ['name', 'type', 'order', 'description', 'icon', 'is_deeplink_only'];
|
||||
|
||||
protected $casts = [
|
||||
'order' => 'integer',
|
||||
'is_deeplink_only' => 'boolean',
|
||||
];
|
||||
|
||||
protected $appends = ['icon_url'];
|
||||
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);
|
||||
|
||||
+19
-1
@@ -21,7 +21,12 @@ class Media extends Model
|
||||
'external_url',
|
||||
'duration',
|
||||
'visibility',
|
||||
'is_premium'
|
||||
'is_premium',
|
||||
'is_deeplink_only'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_deeplink_only' => 'boolean',
|
||||
];
|
||||
protected $appends = [
|
||||
'average_rating',
|
||||
@@ -37,6 +42,7 @@ class Media extends Model
|
||||
'is_liked',
|
||||
'likes_count',
|
||||
'url',
|
||||
'deep_link',
|
||||
];
|
||||
public function image()
|
||||
{
|
||||
@@ -89,6 +95,18 @@ public function getUrlAttribute()
|
||||
|
||||
return $this->external_url;
|
||||
}
|
||||
|
||||
// Public deep link for this media (canonical aramejan.com form).
|
||||
public function getDeepLinkAttribute(): ?string
|
||||
{
|
||||
$canonical = config('deeplinks.media_pattern');
|
||||
|
||||
if ($canonical) {
|
||||
return rtrim(str_replace('{id}', $this->id, $canonical), '/');
|
||||
}
|
||||
|
||||
return url('/media/' . $this->id);
|
||||
}
|
||||
// is_saved / saved_count come from the HasSaves trait (saved_items table),
|
||||
// so the /saves/* endpoints and the media list/show all agree.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user