feat: use xpier media library for uploads and markdown embeds
Store media:ID in post bodies instead of CDN URLs, and keep sablog attach tokens as a fallback. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,8 +6,10 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Xpier\FilamentMediaLibrary\Models\MediaLibrary;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
class Category extends Model implements HasMedia
|
||||
@@ -21,6 +23,7 @@ class Category extends Model implements HasMedia
|
||||
'display_order',
|
||||
'post_count',
|
||||
'description',
|
||||
'cover_media_id',
|
||||
];
|
||||
|
||||
public function posts(): HasMany
|
||||
@@ -28,6 +31,21 @@ class Category extends Model implements HasMedia
|
||||
return $this->hasMany(Post::class);
|
||||
}
|
||||
|
||||
public function coverMedia(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MediaLibrary::class, 'cover_media_id');
|
||||
}
|
||||
|
||||
public function coverImageUrl(): ?string
|
||||
{
|
||||
$libraryUrl = $this->coverMedia?->url;
|
||||
if (filled($libraryUrl)) {
|
||||
return (string) $libraryUrl;
|
||||
}
|
||||
|
||||
return $this->getFirstMedia('cover')?->getUrl();
|
||||
}
|
||||
|
||||
public function getUrlAttribute(): string
|
||||
{
|
||||
return route('category.show', $this->slug ?? $this->id);
|
||||
|
||||
Reference in New Issue
Block a user