medal management

This commit is contained in:
xiaomlove
2022-01-19 23:54:55 +08:00
parent 3fa8fd19c0
commit 64a1f2bb0c
39 changed files with 1282 additions and 171 deletions

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class MedalResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'get_type' => $this->get_type,
'get_type_text' => $this->getTypeText,
'image_large' => $this->image_large,
'image_small' => $this->image_small,
'price' => $this->price,
'duration' => $this->duration,
'description' => $this->description,
'expire_at' => $this->whenPivotLoaded('user_medals', function () {return $this->pivot->expire_at;}),
'user_medal_id' => $this->whenPivotLoaded('user_medals', function () {return $this->pivot->id;}),
];
}
}

View File

@@ -34,6 +34,7 @@ class UserResource extends JsonResource
'leechtime' => $this->leechtime,
'leechtime_text' => mkprettytime($this->leechtime),
'inviter' => new UserResource($this->whenLoaded('inviter')),
'valid_medals' => MedalResource::collection($this->whenLoaded('valid_medals')),
];
if ($request->routeIs('user.me')) {
$out['downloaded_human'] = mksize($this->downloaded);