52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class FileResource extends JsonResource
|
|
{
|
|
public static $wrap = false;
|
|
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
// get deleted at
|
|
$deletedAt = $this->deleted_at;
|
|
// make date readable if it is not null
|
|
if ($deletedAt) {
|
|
$deletedAt = $deletedAt->diffForHumans();
|
|
}
|
|
|
|
$size = $this->size;
|
|
// get if folder
|
|
$isFolder = $this->is_folder;
|
|
// if it is, set $size to getFolderSize()
|
|
if ($isFolder) {
|
|
$size = $this->getFolderSize();
|
|
}
|
|
|
|
return [
|
|
"mime" => $this->mimetype,
|
|
"path" => $this->path,
|
|
"id" => $this->id,
|
|
"parent_id" => $this->parent_id,
|
|
"name" => $this->name,
|
|
"size" => $this->formatSize($size),
|
|
"owner" => $this->user->name,
|
|
"is_folder" => $this->is_folder,
|
|
"created_at" => $this->created_at->diffForHumans(),
|
|
"updated_at" => $this->updated_at->diffForHumans(),
|
|
"created_by" => $this->created_by,
|
|
"updated_by" => $this->updated_by,
|
|
"deleted_at" => $deletedAt,
|
|
"shared_with" => $this->shared_with ? $this->shared_with : null,
|
|
];
|
|
}
|
|
}
|