app/Http/Resources/ForumRowResource.php
/**
     * Transform the resource into an array.
     *
     * @param Request $request
     * @return array
     */
Transform the resource into an array.
@param Request $request
@return array
Transform the resource into an array . @param Request $request @return array
public function toArray($request): array
    {
        $user = Auth::user();
        $comments = $this->commentsNotHidden;
        $unreadContent = $this->unreadContent;
        $unreadCommentsCount = 0;
        if ($user && $unreadContent && $comments) {
            $readAt = $unreadContent->read_at;
            foreach ($comments as $comment) {
                if ($comment->created_at > $readAt && $comment->user_id !== $user->id) {
                    $unreadCommentsCount++;
                }
            }
        }
        return [
            'id' => $this->id,
            'title' => $this->title,
            'slug' => $this->slug,
            'type' => $this->type,
            'status' => $this->status,
            'url' => $this->type === 'internal' ? '/admin/forum/' . $this->id : getForumLinkByTypeAndSlug($this->type, $this->slug),
            'updatedAt' => formatDate($this->updated_at),
            'isNew' => $user && Carbon::now()->subDay() < $this->created_at && !$this->unreadContent,
            'unreadCommentsCount' => $unreadCommentsCount,
            'viewsCount' => $this->views ? $this->views->count : 0,
            'commentsCount' => count($comments),
            'user' => new UserResource($this->user),
            'destinations' => DestinationResource::collection($this->destinations),
            'topics' => TopicResource::collection($this->topics)
        ];
    }
public function toArray ( $ request ) : array { $ user = Auth :: user ( ) ; $ comments = $ this -> commentsNotHidden ; $ unreadContent = $ this -> unreadContent ; $ unreadCommentsCount = 0 ; if ( $ user && $ unreadContent && $ comments ) { $ readAt = $ unreadContent -> read_at ; foreach ( $ comments as $ comment ) { if ( $ comment -> created_at > $ readAt && $ comment -> user_id !== $ user -> id ) { $ unreadCommentsCount ++ ; } } } return [ 'id' => $ this -> id , 'title' => $ this -> title , 'slug' => $ this -> slug , 'type' => $ this -> type , 'status' => $ this -> status , 'url' => $ this -> type === 'internal' ? '/admin/forum/' . $ this -> id : getForumLinkByTypeAndSlug ( $ this -> type , $ this -> slug ) , 'updatedAt' => formatDate ( $ this -> updated_at ) , 'isNew' => $ user && Carbon :: now ( ) -> subDay ( ) < $ this -> created_at && ! $ this -> unreadContent , 'unreadCommentsCount' => $ unreadCommentsCount , 'viewsCount' => $ this -> views ? $ this -> views -> count : 0 , 'commentsCount' => count ( $ comments ) , 'user' => new UserResource ( $ this -> user ) , 'destinations' => DestinationResource :: collection ( $ this -> destinations ) , 'topics' => TopicResource :: collection ( $ this -> topics ) ] ; }
Transform the resource into an array.
Transform the resource into an array .