Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultWrap not work #946

Open
burasuk opened this issue Feb 12, 2025 · 0 comments
Open

defaultWrap not work #946

burasuk opened this issue Feb 12, 2025 · 0 comments

Comments

@burasuk
Copy link

burasuk commented Feb 12, 2025

✏️ Describe the bug

I have "data" object in contoller that return data properly.
But when i try to create custom wrap name as documentation suggest, nothing changes.

↪️ To Reproduce

class ListProductController extends Controller
{

    public function __invoke(Request $request)
    {
        $products = Product::paginate();
        return ProductData::collect($products);

    }
}
class ProductData extends Data
{
  public function __construct(
    public string $name,
    public string $description,
    public string $reference,
  ) {
  }

  public function defaultWrap(): string
  {
    return 'products';
  }
}

reponse:

{
  "current_page": 1,
  "data": [ 
    {
      "name": "autem",
      "description": "Rerum rerum et id qui exercitationem incidunt corporis.",
      "reference": "9417542784724",
    }
]
// rest of properties
}

✅ Expected behavior

{
  "current_page": 1,
  "products": [ // <- THIS
    {
      "name": "autem",
      "description": "Rerum rerum et id qui exercitationem incidunt corporis.",
      "reference": "9417542784724",
    }
]
// rest of properties
}

🖥️ Versions

Laravel: 11.32
Laravel Data: 4.13
PHP: 8.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant