Complete the code to return a resource collection in Laravel.
return [1]::collection($users);
In Laravel, to return a resource collection, you use the resource class with the collection method. Here, UserResource is the correct resource class.
Complete the code to create a resource collection class using Artisan.
php artisan make:resource [1] --collectionThe make:resource command with the --collection flag creates a resource collection class. The conventional name is UserCollection.
Fix the error in the resource collection response code.
return new [1]($users);
When returning a resource collection as a new instance, you should use the collection class, like UserCollection, not the single resource class.
Fill both blanks to define a resource collection class extending the correct base class.
class UserCollection extends [1] { public function toArray($request) { return [2]::collection($this->collection); } }
A resource collection class extends ResourceCollection from Laravel. Inside toArray, it returns a collection of the single resource class, here UserResource.
Fill all three blanks to customize the resource collection's additional data.
public function with($request) { return [ '[1]' => [2], '[3]' => 'Success' ]; }
The with method adds extra data to the resource response. The key meta is used for metadata, and status can indicate success. The value for meta is an array with version info.