Файловый менеджер - Редактировать - /home/clickysoft/public_html/charliapp-v2.clickysoft.net/app/Http/Resources/Admin/ChatResource.php
Назад
<?php namespace App\Http\Resources\Admin; use App\Models\TimelineCharacter; use Illuminate\Http\Resources\Json\JsonResource; use Carbon\Carbon; use App\Models\UserChat; use App\Models\Collaboration; class ChatResource extends JsonResource { public function toArray($request) { $characters =[]; $blockCounts = 0; if(!empty($this->timeline)){ $characters = TimelineCharacter::with("eventBlocks")->whereTimelineId($this->timeline->id)->get(); if (count($characters) > 0){ foreach ($characters as $character) { foreach ($character->eventBlocks as $block) { $blockCounts +=1; } } } } $chapterCards = []; $chapters = []; if (!empty($this->outline)){ foreach ($this->outline->chapters as $chapter) { foreach ($chapter->cards as $card) { $chapterCards[] = [ "id" => $card->id, "card_title" => $card->card_title, "card_description" => $card->card_description, 'created_at' => (new \Carbon\Carbon($this->created_at))->format('F d, Y'), 'updated_at' => (new \Carbon\Carbon($this->updated_at))->format('F d, Y'), 'color_id' => $this->color->id ?? null, 'color' => $card->color->color ?? null, 'color_code' => $card->color->color_code ?? null, 'foreground_color' => $this->color->foreground_color ?? null, 'tasks' => $card->tasks, ]; } $chapters[] = [ "id" => $chapter->id, "chapter_name" => $chapter->chapter_name, 'color_id' => $chapter->color->id ?? null, 'color' => $chapter->color->color ?? null, 'color_code' => $chapter->color->color_code ??null, 'foreground_color' => $this->color->foreground_color ?? null, 'cards' => $chapterCards ]; } } $chatuUser = UserChat::where('chat_id',$this->id)->first(); return [ 'id' => $this->id, 'from_name' => $this->from->name, 'to_name' => $this->toUserName ?? null, 'message' => $this->message, 'attachments' => $this->attachments, 'brainstorm' => !empty($this->brainstorm) ? [ "id" => $this->brainstorm->id, "brainstorm_name" => $this->brainstorm->brainstorm_name, "description" => $this->brainstorm->description, "lines" => count(explode("\n", $this->brainstorm->description)), 'rounds' => BrainstormRoundDetailResource::collection($this->brainstorm->rounds), "audio_file_url" => !empty($this->brainstorm->audio_file) ? asset("storage/audio/" . $this->brainstorm->audio_file) : null, "image_url" => $this->brainstorm->image?->image_url ?? "https://via.placeholder.com/50/EEEEEE/000000/?text=BS", "collaboration" => $this->getCollaboration('brainstorms',$this->brainstorm->id), ] : null, 'timeline' => $this->timeline ? [ "id" => $this->timeline->id ?? null, "name" => $this->timeline->name ?? null, "description" => $this->timeline->description ?? null, "image_url" => $this->timeline->image ? $this->timeline->image->image_url : null, "character_count" => count($characters), "block_count" => $blockCounts, "collaboration" => $this->getCollaboration('timelines',$this->timeline->id), ] : null, 'outline' => $this->outline ? [ "id" => $this->outline->id, "outline_name" => $this->outline->outline_name, "outline_title" => $this->outline->outline_title, "image_url" => $this->outline->image?->image_url ?? "https://via.placeholder.com/50/EEEEEE/000000/?text=OL", 'chapters' => $chapters, "collaboration" => $this->getCollaboration('outlines',$this->outline->id), ] : null, 'plot_planner' => $this->plot_planner ? [ "id" => $this->plot_planner->id, "plot_planner_name" => $this->plot_planner->plot_planner_name, "image_url" => $this->plot_planner->image?->image_url ?? "https://via.placeholder.com/50/EEEEEE/000000/?text=PL", "collaboration" => $this->getCollaboration('plot_planners',$this->plot_planner->id), ] : null, 'book' => $this->book ? [ "id" => $this->book->id, "book_name" => $this->book->book_name, "image_url" => $this->book->image?->image_url ?? "https://via.placeholder.com/50/EEEEEE/000000/?text=B", "collaboration" => $this->getCollaboration('books',$this->book->id), ] : null, 'series' => $this->series ? [ "id" => $this->series->id, "series_name" => $this->series->series_name, "image_url" => $this->series->image?->image_url ?? "https://via.placeholder.com/50/EEEEEE/000000/?text=S", ] : null, 'parent_id' => $this->parent_id, 'hearts' => count($this->hearts), 'thumbs_up' => count($this->thumbs_up), 'thumbs_down' => count($this->thumbs_down), 'question_marks' => count($this->question_marks), 'avatar' => getProfileImage($this->from), 'is_read' => $this->is_read, 'contact_id' => !empty($chatuUser)? $chatuUser->contact_id:'', 'is_mine' => $this->from_id == auth()->id(), 'message_time' => [ "timestamp" => $this->created_at, "readable" => Carbon::parse($this->created_at)->diffForHumans() ], 'replies' => $this->replies->isEmpty() ? [] : $this->replies ]; } public function getCollaboration($type,$id){ $collaboration = null; $is_mine = $this->from_id == auth()->id(); if (!$is_mine) { $collaboration = Collaboration::where('user_id',auth()->id()) ->where('collaboratable_type',$type) ->where('collaboratable_id',$id) ->first(); if (!$collaboration) { $collaboration = null; } } return $collaboration; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка