app/Http/Resources/UserPublicProfileResource.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)
    {
        $destinationsHaveBeen = $this->destinationHaveBeen;
        $destinationWantsToGo = $this->destinationWantsToGo;
        $countriesVisited = $citiesVisited = [];
        $countryPercentage = 0;
        foreach ($destinationsHaveBeen as $destination) {
            if ($destination->isCountry()) {
                $countriesVisited[] = $destination;
            } else if ($destination->isCity() || $destination->isPlace() ) {
                $citiesVisited[] = $destination;
            }
        }
        if (count($countriesVisited)) {
            $countryPercentage = round(count($countriesVisited) / 195 * 100);
        }
        return [
            'id' => $this->id,
            'name' => $this->name,
            'rank' => $this->rank,
            'rankName' => $this->rankName,
            'avatar' => $this->profileImage ? env('IMAGE_PATH') . '/user_profile/small_square/' . $this->profileImage->filename : null,
            'isAdmin' => $this->hasRole('admin'),
            'joinedDate' => $this->created_at->diffForHumans(),
            'description' => $this->description,
            'liked' => $this->liked(),
            'disliked' => $this->disliked(),
            'postCount' => $this->contentCount(),
            'commentCount' => $this->commentCount(),
            'countriesVisited' => DestinationResource::collection($countriesVisited),
            'citiesVisited' => DestinationResource::collection($citiesVisited),
            'wantsToGo' => DestinationResource::collection($destinationWantsToGo),
            'countryPercentage' => $countryPercentage
        ];
    }
public function toArray ( $ request ) { $ destinationsHaveBeen = $ this -> destinationHaveBeen ; $ destinationWantsToGo = $ this -> destinationWantsToGo ; $ countriesVisited = $ citiesVisited = [ ] ; $ countryPercentage = 0 ; foreach ( $ destinationsHaveBeen as $ destination ) { if ( $ destination -> isCountry ( ) ) { $ countriesVisited [ ] = $ destination ; } else if ( $ destination -> isCity ( ) || $ destination -> isPlace ( ) ) { $ citiesVisited [ ] = $ destination ; } } if ( count ( $ countriesVisited ) ) { $ countryPercentage = round ( count ( $ countriesVisited ) / 195 * 100 ) ; } return [ 'id' => $ this -> id , 'name' => $ this -> name , 'rank' => $ this -> rank , 'rankName' => $ this -> rankName , 'avatar' => $ this -> profileImage ? env ( 'IMAGE_PATH' ) . '/user_profile/small_square/' . $ this -> profileImage -> filename : null , 'isAdmin' => $ this -> hasRole ( 'admin' ) , 'joinedDate' => $ this -> created_at -> diffForHumans ( ) , 'description' => $ this -> description , 'liked' => $ this -> liked ( ) , 'disliked' => $ this -> disliked ( ) , 'postCount' => $ this -> contentCount ( ) , 'commentCount' => $ this -> commentCount ( ) , 'countriesVisited' => DestinationResource :: collection ( $ countriesVisited ) , 'citiesVisited' => DestinationResource :: collection ( $ citiesVisited ) , 'wantsToGo' => DestinationResource :: collection ( $ destinationWantsToGo ) , 'countryPercentage' => $ countryPercentage ] ; }
Transform the resource into an array.
Transform the resource into an array .
/** @var Destination $destination */ //'continentsVisited' => DestinationResource::collection($continentsVisited),