diff options
author | Michael Weimann <mail@michael-weimann.eu> | 2019-10-31 20:02:34 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2019-11-10 22:10:11 +0100 |
commit | 6534191d59521e1e5a88638b1c6a1c77f74dd12a (patch) | |
tree | d381a16b7287c2ff3cff814a793ebc27bdeb4eac /src | |
parent | 8b5b9e2c65193171a12bf99a8df860a66e6900a5 (diff) |
Migrate news to model class
Diffstat (limited to 'src')
-rw-r--r-- | src/Models/News/News.php | 30 | ||||
-rw-r--r-- | src/Models/User/User.php | 10 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/Models/News/News.php b/src/Models/News/News.php new file mode 100644 index 00000000..ae67752b --- /dev/null +++ b/src/Models/News/News.php @@ -0,0 +1,30 @@ +<?php +declare(strict_types=1); + +namespace Engelsystem\Models\News; + +use Engelsystem\Models\User\UsesUserModel; +use Illuminate\Database\Eloquent\Model; + +/** + * This class represents a news item. + */ +class News extends Model +{ + use UsesUserModel; + + protected $casts = [ + 'is_meeting' => 'boolean', + ]; + + protected $attributes = [ + 'is_meeting' => false, + ]; + + protected $fillable = [ + 'title', + 'text', + 'is_meeting', + 'user_id', + ]; +} diff --git a/src/Models/User/User.php b/src/Models/User/User.php index af213c4e..cca96dbe 100644 --- a/src/Models/User/User.php +++ b/src/Models/User/User.php @@ -4,6 +4,8 @@ namespace Engelsystem\Models\User; use Carbon\Carbon; use Engelsystem\Models\BaseModel; +use Engelsystem\Models\News\News; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Query\Builder as QueryBuilder; @@ -95,4 +97,12 @@ class User extends BaseModel ->hasOne(State::class) ->withDefault(); } + + /** + * @return HasMany + */ + public function news(): HasMany + { + return $this->hasMany(News::class); + } } |