DEV Community

Cover image for Laravel: API Resources: With or Without "data"?
Akhilesh Gupta
Akhilesh Gupta

Posted on

Laravel: 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 (0)