Laravel API data envelope
retained text
<!-- SC_OFF --><div class="md"><p>i'm having a hard time deciding which approach i should implement. i'm developing a Laravel api which is consumed by Vue & Nuxt and i didn't noticed that i actually implemented two approaches of the returned response:</p> <p><strong>[1]</strong></p> <pre><code>return ArticleResource::collection($articles); </code></pre> <p>this returns a JSON like this:</p> <pre><code>{ "id": 1, "title": "My Article" } </code></pre> <p><strong>[2]</strong></p> <pre><code> return response()->json([ 'data' => new ArticleResource($article), 'success' => true, 'message' => 'OK', ]); </code></pre> <p>JSON:</p> <pre><code>{ "data": { // output of ArticleResource transformed $article }, "success": true, "message": "OK" } </code></pre> <p>considering that the API and frontend are private repositories. does wrapping all of the response inside 'data' makes sense or should i just stick on [1] for less nesting? what do you guys think what do you usually do with your years of experience?</p> </div><!-- SC_ON -->   submitted by   <a href="https://www.reddit.com/user/Totoro-Caelum"> /u/Totoro-Caelum </a> <br /> <span><a href="https://www.reddit.com/r/webdev/comments/1twpn7l/laravel_api_data_envelope/">[link]</a></span>   <span><a href="https://www.reddit.com/r/webdev/comments/1twpn7l/laravel_api_data_envelope/">[comments]</a></span>document fetched 2026-06-05 09:35