DEV Community

Cover image for Laravel | How to remove `data` from API Resources
Sajad DP
Sajad DP

Posted on • Edited on

1 1

Laravel | How to remove `data` from API Resources

Usually, Eloquent API Resources return content on the "data" section.

We can remove the data section just with add JsonResource::withoutWrapping(); in app/Providers/AppServiceProvider.php.

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        JsonResource::withoutWrapping();
    }
}
Enter fullscreen mode Exit fullscreen mode

If you know a better way, please teach me in the comments :)

Can you plz buy me a book?

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay