summaryrefslogtreecommitdiff
path: root/src/Models
diff options
context:
space:
mode:
Diffstat (limited to 'src/Models')
-rw-r--r--src/Models/News.php25
-rw-r--r--src/Models/NewsComment.php48
-rw-r--r--src/Models/User/User.php11
3 files changed, 78 insertions, 6 deletions
diff --git a/src/Models/News.php b/src/Models/News.php
index 55ab9c1d..febaae3a 100644
--- a/src/Models/News.php
+++ b/src/Models/News.php
@@ -6,15 +6,19 @@ namespace Engelsystem\Models;
use Carbon\Carbon;
use Engelsystem\Models\User\UsesUserModel;
+use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Query\Builder as QueryBuilder;
/**
- * @property int $id
- * @property string $title
- * @property string $text
- * @property bool $is_meeting
- * @property Carbon|null $created_at
- * @property Carbon|null $updated_at
+ * @property int $id
+ * @property string $title
+ * @property string $text
+ * @property bool $is_meeting
+ * @property Carbon|null $created_at
+ * @property Carbon|null $updated_at
+ *
+ * @property-read Collection|NewsComment[] $comments
*
* @method static QueryBuilder|LogEntry[] whereId($value)
* @method static QueryBuilder|LogEntry[] whereTitle($value)
@@ -42,4 +46,13 @@ class News extends BaseModel
'is_meeting',
'user_id',
];
+
+ /**
+ * @return HasMany
+ */
+ public function comments(): HasMany
+ {
+ return $this->hasMany(NewsComment::class)
+ ->orderBy('created_at');
+ }
}
diff --git a/src/Models/NewsComment.php b/src/Models/NewsComment.php
new file mode 100644
index 00000000..c2697350
--- /dev/null
+++ b/src/Models/NewsComment.php
@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Engelsystem\Models;
+
+use Carbon\Carbon;
+use Engelsystem\Models\User\UsesUserModel;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Query\Builder as QueryBuilder;
+
+/**
+ * This class represents a news comment.
+ *
+ * @property int $id
+ * @property int $news_id
+ * @property string $text
+ * @property News $news
+ * @property Carbon|null $created_at
+ * @property Carbon|null $updated_at
+ *
+ * @method static QueryBuilder|LogEntry[] whereId($value)
+ * @method static QueryBuilder|LogEntry[] whereText($value)
+ * @method static QueryBuilder|LogEntry[] whereCreatedAt($value)
+ * @method static QueryBuilder|LogEntry[] whereUpdatedAt($value)
+ */
+class NewsComment extends BaseModel
+{
+ use UsesUserModel;
+
+ /** @var bool Enable timestamps */
+ public $timestamps = true;
+
+ /** @var string[] */
+ protected $fillable = [
+ 'news_id',
+ 'text',
+ 'user_id',
+ ];
+
+ /**
+ * @return BelongsTo
+ */
+ public function news(): BelongsTo
+ {
+ return $this->belongsTo(News::class);
+ }
+}
diff --git a/src/Models/User/User.php b/src/Models/User/User.php
index 058f9a8c..6db4de7e 100644
--- a/src/Models/User/User.php
+++ b/src/Models/User/User.php
@@ -5,6 +5,8 @@ namespace Engelsystem\Models\User;
use Carbon\Carbon;
use Engelsystem\Models\BaseModel;
use Engelsystem\Models\News;
+use Engelsystem\Models\NewsComment;
+use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Query\Builder as QueryBuilder;
@@ -23,6 +25,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
* @property-read QueryBuilder|PersonalData $personalData
* @property-read QueryBuilder|Settings $settings
* @property-read QueryBuilder|State $state
+ * @property-read Collection|NewsComment[] $newsComments
*
* @method static QueryBuilder|User whereId($value)
* @method static QueryBuilder|User[] whereName($value)
@@ -105,4 +108,12 @@ class User extends BaseModel
{
return $this->hasMany(News::class);
}
+
+ /**
+ * @return HasMany
+ */
+ public function newsComments(): HasMany
+ {
+ return $this->hasMany(NewsComment::class);
+ }
}