Files
UNIT3D-Community-Edition/app/Models/Subscription.php
HDVinnie 8a03bec818 add: model docblocks
- this resolves some larastan property issues but in return has revealed quite a few issues with our castings and such. baseline has been regenerated so we can work through them. The properties in docblocks are in order and match everything in DB schema wise.
2024-02-07 16:39:43 -05:00

91 lines
2.5 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Models;
use App\Traits\Auditable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Subscription.
*
* @property int $id
* @property int $user_id
* @property int|null $forum_id
* @property int|null $topic_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*/
class Subscription extends Model
{
use Auditable;
use HasFactory;
/**
* Belongs To A User.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<User, self>
*/
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class)->withDefault([
'username' => 'System',
'id' => '1',
]);
}
/**
* Belongs To A Topic.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Topic, self>
*/
public function topic(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Topic::class);
}
/**
* Belongs To A Forum.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<Forum, self>
*/
public function forum(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Forum::class);
}
/**
* Only include subscriptions of a forum.
*
* @param Builder<Subscription> $query
* @return Builder<Subscription>
*/
public function scopeOfForum(Builder $query, int $forum_id): Builder
{
return $query->where('forum_id', '=', $forum_id);
}
/**
* Only include subscriptions of a topic.
*
* @param Builder<Subscription> $query
* @return Builder<Subscription>
*/
public function scopeOfTopic($query, int $topic_id): Builder
{
return $query->where('topic_id', '=', $topic_id);
}
}