DEV Community

Cover image for Laravel 9 - API Resources: With or Without "data"?
Sandro Jhuliano Cagara
Sandro Jhuliano Cagara

Posted on

3 2

Laravel 9 - API Resources: With or Without "data"?

If you use Eloquent API Resources to return data, they will be automatically wrapped in 'data'.

If you want to remove it, add JsonResource::withoutWrapping(); in app/Providers/AppServiceProvider.php.

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

Top comments (2)

Collapse
 
emerie55 profile image
Innocent Chiemerie Feargod

Still in Laravel 8

Collapse
 
sandrocagara profile image
Sandro Jhuliano Cagara • Edited

YES

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

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

Okay