Welcome Guest, Not a member yet? Register   Sign In
Can I make an array filled with an entity object?
#2

(This post was last modified: 06-13-2022, 04:19 AM by AgBRAT.)

I was able to create a multidimensional array of my entity class Image.php and fill this array using these functions defined in my ImageModel.php:
PHP Code:
public function fillImageEntity(string $viewkey)
    {
        $imageData $this->builder()
            ->where('viewkey'$viewkey)
            ->get()
            ->getRowArray();

        $image = new \App\Entities\Image();

        $image->fill($imageData);
        $image->setDislikeCount($viewkey);
        $image->setLikeCount($viewkey);
        $image->setViewCount($viewkey);
        $image->setFavoriteCount($viewkey);
        $image->setCommentCount($viewkey);
        $image->setRating($viewkey);
        $image->setUserDisliked($viewkey);
        $image->setUserLiked($viewkey);
        $image->setUserViewed($viewkey);
        $image->setUserFavorited($viewkey);
        $image->setUserCommented($viewkey);
        $image->setUserSubscribed($imageData['uploader']);

        return $image;
    }

    public function getEntireGallery()
    {
        $images $this->builder()
            ->orderBy('modified_at''DESC')
            ->get()
            ->getResultArray();

        foreach ($images as $image) {

            $gallery[$image['id']] = $this->fillImageEntity($image['viewkey']);
        }

        return $gallery
Reply


Messages In This Thread
RE: Can I make an array filled with an entity object? - by AgBRAT - 06-13-2022, 04:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB