From 26b8d2b92190de6ce4bbf6ccbb3f1a4f1a735d1d Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Tue, 12 Nov 2019 21:49:43 +0100 Subject: Introduce the NewsComments model --- src/Models/News.php | 26 ++++++++++++++++++------- src/Models/NewsComment.php | 47 ++++++++++++++++++++++++++++++++++++++++++++++ src/Models/User/User.php | 11 +++++++++++ 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/Models/NewsComment.php (limited to 'src/Models') diff --git a/src/Models/News.php b/src/Models/News.php index 55ab9c1d..6f0e96fa 100644 --- a/src/Models/News.php +++ b/src/Models/News.php @@ -1,20 +1,23 @@ hasMany(NewsComment::class) + ->orderBy('created_at'); + } } diff --git a/src/Models/NewsComment.php b/src/Models/NewsComment.php new file mode 100644 index 00000000..aed1926a --- /dev/null +++ b/src/Models/NewsComment.php @@ -0,0 +1,47 @@ +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); + } } -- cgit v1.2.3-70-g09d2 From 17192a2c412a6f5c4d8c10d8d25ef1a680bbce01 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Tue, 12 Nov 2019 22:04:39 +0100 Subject: Adapt code style to PSR-12 --- db/migrations/2019_11_12_000000_create_news_comments_table.php | 1 + src/Models/News.php | 1 + src/Models/NewsComment.php | 1 + tests/Unit/Models/NewsCommentsTest.php | 1 + 4 files changed, 4 insertions(+) (limited to 'src/Models') diff --git a/db/migrations/2019_11_12_000000_create_news_comments_table.php b/db/migrations/2019_11_12_000000_create_news_comments_table.php index cb7065b8..00cf99b2 100644 --- a/db/migrations/2019_11_12_000000_create_news_comments_table.php +++ b/db/migrations/2019_11_12_000000_create_news_comments_table.php @@ -1,4 +1,5 @@