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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ForumPost extends Model
|
||||
@@ -18,16 +21,42 @@ class ForumPost extends Model
|
||||
public $incrementing = true;
|
||||
|
||||
protected $casts = [
|
||||
'is_edited' => 'boolean',
|
||||
'edited_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function thread()
|
||||
public function thread(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ForumThread::class, 'thread_id');
|
||||
}
|
||||
|
||||
public function attachments()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(ForumAttachment::class, 'post_id');
|
||||
}
|
||||
|
||||
public function scopeInThread(Builder $query, int $threadId): Builder
|
||||
{
|
||||
return $query->where('thread_id', $threadId);
|
||||
}
|
||||
|
||||
public function scopeVisible(Builder $query): Builder
|
||||
{
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function scopePinned(Builder $query): Builder
|
||||
{
|
||||
return $query->whereHas('thread', fn (Builder $threadQuery) => $threadQuery->where('is_pinned', true));
|
||||
}
|
||||
|
||||
public function scopeRecent(Builder $query): Builder
|
||||
{
|
||||
return $query->orderByDesc('created_at')->orderByDesc('id');
|
||||
}
|
||||
}
|
||||
|
||||
40
app/Models/ForumPostReport.php
Normal file
40
app/Models/ForumPostReport.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ForumPostReport extends Model
|
||||
{
|
||||
protected $table = 'forum_post_reports';
|
||||
|
||||
protected $fillable = [
|
||||
'post_id',
|
||||
'thread_id',
|
||||
'reporter_user_id',
|
||||
'reason',
|
||||
'status',
|
||||
'source_url',
|
||||
'reported_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'reported_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function post(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ForumPost::class, 'post_id');
|
||||
}
|
||||
|
||||
public function thread(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ForumThread::class, 'thread_id');
|
||||
}
|
||||
|
||||
public function reporter(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'reporter_user_id');
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ForumThread extends Model
|
||||
@@ -18,16 +21,43 @@ class ForumThread extends Model
|
||||
public $incrementing = true;
|
||||
|
||||
protected $casts = [
|
||||
'is_locked' => 'boolean',
|
||||
'is_pinned' => 'boolean',
|
||||
'last_post_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function category()
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ForumCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
public function posts()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function posts(): HasMany
|
||||
{
|
||||
return $this->hasMany(ForumPost::class, 'thread_id');
|
||||
}
|
||||
|
||||
public function scopeVisible(Builder $query): Builder
|
||||
{
|
||||
return $query->where('visibility', 'public');
|
||||
}
|
||||
|
||||
public function scopePinned(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_pinned', true);
|
||||
}
|
||||
|
||||
public function scopeRecent(Builder $query): Builder
|
||||
{
|
||||
return $query->orderByDesc('last_post_at')->orderByDesc('id');
|
||||
}
|
||||
|
||||
public function scopeInCategory(Builder $query, int $categoryId): Builder
|
||||
{
|
||||
return $query->where('category_id', $categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,13 @@ class User extends Authenticatable
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'username',
|
||||
'username_changed_at',
|
||||
'onboarding_step',
|
||||
'name',
|
||||
'email',
|
||||
'is_active',
|
||||
'needs_password_reset',
|
||||
'password',
|
||||
'role',
|
||||
];
|
||||
@@ -46,6 +51,7 @@ class User extends Authenticatable
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'username_changed_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user