Auth: convert auth views and verification email to Nova layout
This commit is contained in:
@@ -2,7 +2,12 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class ForumCategory extends Model
|
||||
{
|
||||
@@ -14,13 +19,77 @@ class ForumCategory extends Model
|
||||
|
||||
public $incrementing = true;
|
||||
|
||||
public function parent()
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ForumCategory::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function threads()
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(ForumCategory::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function threads(): HasMany
|
||||
{
|
||||
return $this->hasMany(ForumThread::class, 'category_id');
|
||||
}
|
||||
|
||||
public function postsThroughThreads(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
ForumPost::class,
|
||||
ForumThread::class,
|
||||
'category_id',
|
||||
'thread_id',
|
||||
'id',
|
||||
'id'
|
||||
);
|
||||
}
|
||||
|
||||
public function lastThread(): HasOne
|
||||
{
|
||||
return $this->hasOne(ForumThread::class, 'category_id')->latestOfMany('last_post_at');
|
||||
}
|
||||
|
||||
public function scopeOrdered(Builder $query): Builder
|
||||
{
|
||||
return $query->orderBy('position')->orderBy('id');
|
||||
}
|
||||
|
||||
public function scopeRoots(Builder $query): Builder
|
||||
{
|
||||
return $query->whereNull('parent_id');
|
||||
}
|
||||
|
||||
public function scopeWithForumStats(Builder $query): Builder
|
||||
{
|
||||
return $query
|
||||
->withCount(['threads as thread_count'])
|
||||
->withCount(['postsThroughThreads as post_count'])
|
||||
->with(['lastThread' => function ($relationQuery) {
|
||||
$relationQuery->select([
|
||||
'forum_threads.id',
|
||||
'forum_threads.category_id',
|
||||
'forum_threads.last_post_at',
|
||||
'forum_threads.updated_at',
|
||||
]);
|
||||
}]);
|
||||
}
|
||||
|
||||
public function getPreviewImageAttribute(): string
|
||||
{
|
||||
$slug = (string) ($this->slug ?? '');
|
||||
$map = (array) config('forum.preview_images.map', []);
|
||||
$default = (string) config('forum.preview_images.default', '/images/forum/default.jpg');
|
||||
|
||||
if ($slug !== '' && !empty($map[$slug])) {
|
||||
return (string) $map[$slug];
|
||||
}
|
||||
|
||||
if ($slug !== '') {
|
||||
return '/images/forum/defaults/' . $slug . '.jpg';
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user