/home/bdqbpbxa/api-uniferx.goodface.com.ua/app/Http/Resources/Pages/Resource/CropsCollection.php
<?php

namespace App\Http\Resources\Pages\Resource;

use App\Http\Resources\Pages\Blog\PostResource;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

class CropsCollection extends ResourceCollection
{
    protected string|null $language;
    protected string|null $country;
    protected string|null $type;
    public bool $full;

    public function language($value): static
    {
        $this->language = $value;
        return $this;
    }
    public function country($value): static
    {
        $this->country = $value;
        return $this;
    }

    public function full($value = true): static
    {
        $this->full = $value;
        return $this;
    }

    public function type($value = false): static
    {
        $this->type = $value;
        return $this;
    }

    public function toArray($request){
        return $this->collection->map(function(CropsResource $resource) use($request){
            return $resource->language($this->language)->country($this->country)->type($this->type ?? false)->full($this->full ?? true)->toArray($request);
        })->all();
    }
}