Implemented the authenticated admin contact system.
This commit is contained in:
21
app/Models/SupportAttachment.php
Normal file
21
app/Models/SupportAttachment.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\SupportAttachmentFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['support_message_id', 'disk', 'path', 'original_name', 'mime_type', 'size'])]
|
||||
class SupportAttachment extends Model
|
||||
{
|
||||
/** @use HasFactory<SupportAttachmentFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public function message(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SupportMessage::class, 'support_message_id');
|
||||
}
|
||||
}
|
||||
92
app/Models/SupportConversation.php
Normal file
92
app/Models/SupportConversation.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\SupportConversationFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
#[Fillable(['user_id', 'category', 'subject', 'status', 'last_message_at'])]
|
||||
class SupportConversation extends Model
|
||||
{
|
||||
/** @use HasFactory<SupportConversationFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public const CATEGORY_BUG = 'bug';
|
||||
|
||||
public const CATEGORY_SUGGESTION = 'suggestion';
|
||||
|
||||
public const CATEGORY_CHANNEL_REQUEST = 'channel_request';
|
||||
|
||||
public const CATEGORY_OTHER = 'other';
|
||||
|
||||
public const STATUS_OPEN = 'open';
|
||||
|
||||
public const STATUS_CLOSED = 'closed';
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function categoryLabels(): array
|
||||
{
|
||||
return [
|
||||
self::CATEGORY_BUG => 'Bug report',
|
||||
self::CATEGORY_SUGGESTION => 'Suggestion',
|
||||
self::CATEGORY_CHANNEL_REQUEST => 'Channel request',
|
||||
self::CATEGORY_OTHER => 'Other',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function categories(): array
|
||||
{
|
||||
return array_keys(self::categoryLabels());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function statuses(): array
|
||||
{
|
||||
return [
|
||||
self::STATUS_OPEN,
|
||||
self::STATUS_CLOSED,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'last_message_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function messages(): HasMany
|
||||
{
|
||||
return $this->hasMany(SupportMessage::class);
|
||||
}
|
||||
|
||||
public function latestMessage(): HasOne
|
||||
{
|
||||
return $this->hasOne(SupportMessage::class)->latestOfMany();
|
||||
}
|
||||
|
||||
public function isOpen(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_OPEN;
|
||||
}
|
||||
}
|
||||
32
app/Models/SupportMessage.php
Normal file
32
app/Models/SupportMessage.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\SupportMessageFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['support_conversation_id', 'user_id', 'body'])]
|
||||
class SupportMessage extends Model
|
||||
{
|
||||
/** @use HasFactory<SupportMessageFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public function conversation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SupportConversation::class, 'support_conversation_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(SupportAttachment::class);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,16 @@ class User extends Authenticatable
|
||||
return $this->hasMany(Follow::class);
|
||||
}
|
||||
|
||||
public function supportConversations(): HasMany
|
||||
{
|
||||
return $this->hasMany(SupportConversation::class);
|
||||
}
|
||||
|
||||
public function supportMessages(): HasMany
|
||||
{
|
||||
return $this->hasMany(SupportMessage::class);
|
||||
}
|
||||
|
||||
public function isSuspended(): bool
|
||||
{
|
||||
return $this->suspended_at !== null;
|
||||
|
||||
Reference in New Issue
Block a user