DEV Community

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

Posted on

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