implement uploading file

This commit is contained in:
2026-05-01 02:02:34 +03:30
parent 4776af5c2a
commit 12b6bb4d76
11 changed files with 589 additions and 24 deletions

View File

@@ -5,8 +5,9 @@ namespace App\Models;
use Database\Factories\MessageFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Number;
#[Fillable(['conversation_id', 'user_id', 'type', 'body', 'metadata', 'edited_at'])]
class Message extends Model
@@ -16,6 +17,8 @@ class Message extends Model
public const string TypeText = 'text';
public const string TypeFile = 'file';
/**
* @return array<string, string>
*/
@@ -50,4 +53,51 @@ class Message extends Model
{
return $this->belongsTo(User::class);
}
public function isFile(): bool
{
return $this->type === self::TypeFile;
}
public function attachmentDisk(): string
{
return (string) data_get($this->metadata, 'disk', 'local');
}
public function attachmentPath(): ?string
{
$path = data_get($this->metadata, 'path');
return is_string($path) && $path !== '' ? $path : null;
}
public function attachmentName(): string
{
$name = data_get($this->metadata, 'original_name');
if (is_string($name) && $name !== '') {
return $name;
}
return $this->body ?: __('Attachment');
}
public function attachmentMimeType(): ?string
{
$mimeType = data_get($this->metadata, 'mime_type');
return is_string($mimeType) && $mimeType !== '' ? $mimeType : null;
}
public function attachmentSize(): int
{
return (int) data_get($this->metadata, 'size', 0);
}
public function formattedAttachmentSize(): string
{
$size = $this->attachmentSize();
return $size > 0 ? Number::fileSize($size) : __('Unknown size');
}
}