diff --git a/app/Models/LibraryItem.php b/app/Models/LibraryItem.php index 5e3a7e0e..02402f4c 100644 --- a/app/Models/LibraryItem.php +++ b/app/Models/LibraryItem.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Support\Facades\Cookie; +use Spatie\Comments\Models\Concerns\HasComments; use Spatie\EloquentSortable\Sortable; use Spatie\EloquentSortable\SortableTrait; use Spatie\Image\Manipulations; @@ -24,6 +25,7 @@ class LibraryItem extends Model implements HasMedia, Sortable use SortableTrait; use HasStatuses; use HasSlug; + use HasComments; /** * The attributes that aren't mass assignable. @@ -41,14 +43,6 @@ class LibraryItem extends Model implements HasMedia, Sortable 'library_id' => 'integer', ]; - public function getSlugOptions(): SlugOptions - { - return SlugOptions::create() - ->generateSlugsFrom(['name']) - ->saveSlugsTo('slug') - ->usingLanguage(Cookie::get('lang', config('app.locale'))); - } - protected static function booted() { static::creating(function ($model) { @@ -58,6 +52,14 @@ class LibraryItem extends Model implements HasMedia, Sortable }); } + public function getSlugOptions(): SlugOptions + { + return SlugOptions::create() + ->generateSlugsFrom(['name']) + ->saveSlugsTo('slug') + ->usingLanguage(Cookie::get('lang', config('app.locale'))); + } + public function registerMediaConversions(Media $media = null): void { $this @@ -101,4 +103,26 @@ class LibraryItem extends Model implements HasMedia, Sortable { return $this->belongsToMany(Library::class); } + + /* + * This string will be used in notifications on what a new comment + * was made. + */ + public function commentableName(): string + { + return __('Library Item'); + } + + /* + * This URL will be used in notifications to let the user know + * where the comment itself can be read. + */ + public function commentUrl(): string + { + if ($this->type === 'markdown_article') { + return url()->route('article.view', ['libraryItem' => $this]); + } else { + return url()->route('libraryItem.view', ['libraryItem' => $this]); + } + } } diff --git a/resources/views/livewire/news/intern-article-view.blade.php b/resources/views/livewire/news/intern-article-view.blade.php index 915b0ff0..4d89736a 100644 --- a/resources/views/livewire/news/intern-article-view.blade.php +++ b/resources/views/livewire/news/intern-article-view.blade.php @@ -54,6 +54,9 @@ {{ $libraryItem->main_image_caption ?? $libraryItem->name }} +