author thumbnail in file

This commit is contained in:
Čarodej
2021-10-22 17:48:42 +02:00
parent 841c1db54a
commit c9631a9727
6 changed files with 183 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
<?php
namespace Domain\Files\Models;
use App\Users\Models\User;
use Illuminate\Support\Str;
use Laravel\Scout\Searchable;
use Domain\Sharing\Models\Share;
@@ -164,6 +165,11 @@ class File extends Model
return $this->hasOne(Share::class, 'item_id', 'id');
}
public function owner(): HasOne
{
return $this->hasOne(User::class, 'id', 'user_id');
}
public function toSearchableArray(): array
{
$name = mb_convert_encoding(

View File

@@ -1,4 +1,5 @@
<?php
namespace Domain\Files\Resources;
use Carbon\Carbon;
@@ -25,17 +26,17 @@ class FileResource extends JsonResource
'id' => $this->id,
'type' => $this->type,
'attributes' => [
'filesize' => $fileSize,
'name' => $this->name,
'basename' => $this->basename,
'mimetype' => $this->mimetype,
'file_url' => $this->file_url,
'thumbnail' => $this->thumbnail,
'metadata' => $this->metadata,
'parent_id' => $this->parent_id,
'updated_at' => $this->updated_at,
'created_at' => Carbon::parse($this->created_at)->diffForHumans(),
'deleted_at' => $this->deleted_at,
'filesize' => $fileSize,
'name' => $this->name,
'basename' => $this->basename,
'mimetype' => $this->mimetype,
'file_url' => $this->file_url,
'thumbnail' => $this->thumbnail,
'metadata' => $this->metadata,
'parent_id' => $this->parent_id,
'updated_at' => $this->updated_at,
'created_at' => Carbon::parse($this->created_at)->diffForHumans(),
'deleted_at' => $this->deleted_at,
/*'updated_at' => format_date(
set_time_by_user_timezone($this->updated_at), __t('time')
),
@@ -44,10 +45,10 @@ class FileResource extends JsonResource
),*/
],
'relationships' => [
$this->mergeWhen($this->shared, fn () => [
$this->mergeWhen($this->shared, fn() => [
'shared' => new ShareResource($this->shared),
]),
$this->mergeWhen($this->parent, fn () => [
$this->mergeWhen($this->parent, fn() => [
'parent' => [
'data' => [
'type' => 'folder',
@@ -58,6 +59,19 @@ class FileResource extends JsonResource
],
],
]),
$this->mergeWhen($this->owner, fn() => [
'user' => [
'data' => [
'type' => 'user',
'id' => $this->user_id,
'attributes' => [
'name' => $this->owner->settings->name,
'avatar' => $this->owner->settings->avatar,
'color' => $this->owner->settings->color,
],
],
],
]),
],
],
];