Kommentare mit Antworten unter Neuigkeiten
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m33s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 8m0s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 8m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m10s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m19s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m21s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m33s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 8m0s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 8m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m10s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m19s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m21s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f3f2d23961
commit
9320d602a8
117 changed files with 1015 additions and 423 deletions
57
plugins-core/news/src/Models/NewsComment.php
Normal file
57
plugins-core/news/src/Models/NewsComment.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\News\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* Kommentar zu einem Beitrag. Antworten (parent_id) hängen immer am obersten
|
||||
* Kommentar eines Strangs; reply_to_user_id merkt sich, wem geantwortet wurde.
|
||||
*/
|
||||
#[Fillable(['post_id', 'parent_id', 'user_id', 'reply_to_user_id', 'body'])]
|
||||
class NewsComment extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
public const MAX_LENGTH = 3000;
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['edited_at' => 'datetime'];
|
||||
}
|
||||
|
||||
/** @return BelongsTo<NewsPost, $this> */
|
||||
public function post(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(NewsPost::class, 'post_id');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<User, $this> */
|
||||
public function author(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<User, $this> */
|
||||
public function replyTo(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'reply_to_user_id');
|
||||
}
|
||||
|
||||
/** @return BelongsTo<NewsComment, $this> */
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
/** @return HasMany<NewsComment, $this> */
|
||||
public function replies(): HasMany
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_id')->withTrashed()->orderBy('created_at');
|
||||
}
|
||||
}
|
||||
|
|
@ -11,12 +11,13 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
use Inhaus\Plugins\News\Database\Factories\NewsPostFactory;
|
||||
|
||||
#[Fillable([
|
||||
'category_id', 'author_id', 'title', 'slug', 'teaser', 'body',
|
||||
'cover_path', 'is_featured', 'published_at', 'form_id', 'content',
|
||||
'cover_path', 'is_featured', 'published_at', 'form_id', 'content', 'comments_enabled',
|
||||
])]
|
||||
class NewsPost extends Model
|
||||
{
|
||||
|
|
@ -79,6 +80,7 @@ class NewsPost extends Model
|
|||
return [
|
||||
'is_featured' => 'boolean',
|
||||
'content' => 'array',
|
||||
'comments_enabled' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'submitted_at' => 'datetime',
|
||||
'form_id' => 'integer',
|
||||
|
|
@ -153,6 +155,12 @@ class NewsPost extends Model
|
|||
return ['blocks' => filled($this->body) ? [['type' => 'text', 'data' => ['html' => $this->body_html ?? $this->body]]] : []];
|
||||
}
|
||||
|
||||
/** @return HasMany<NewsComment, $this> */
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(NewsComment::class, 'post_id');
|
||||
}
|
||||
|
||||
public function coverUrl(string $variant = 'large'): ?string
|
||||
{
|
||||
return app(Images::class)->url($this->cover_path, $variant);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue