DEV Community

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

Posted on

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)