Files
UNIT3D-Community-Edition/app/Http/Resources/ChatMessageResource.php
T

31 lines
896 B
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Resources;
use App\Helpers\Bbcode;
use ChristofferOK\LaravelEmojiOne\LaravelEmojiOne;
use Illuminate\Http\Resources\Json\JsonResource;
class ChatMessageResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$emojiOne = app()->make(LaravelEmojiOne::class);
return [
'id' => $this->id,
'user' => new ChatUserResource($this->whenLoaded('user')),
'chatroom' => new ChatRoomResource($this->whenLoaded('chatroom')),
'message' => $emojiOne->toImage(Bbcode::parse("[left]{$this->message}[/left]")),
'created_at' => $this->created_at->toIso8601String(),
'updated_at' => $this->updated_at->toIso8601String()
];
}
}