API Resources acts as a transformation layer that sits between our Eloquent models and the JSON responses that are actually returned by our API.
Sample commands for creating the resource class and resource collection using php artisan create a resource class $ php artisan make:resource UserResource Exit fullscreen mode create a resource collection using either $ php artisan make:resource Users --collection $ php artisan make:resource UserCollection
Next, let’s define the inverse relationship on the Book model: app/Book.php public function user() { return $this->belongsTo(User::class); }
Unlike when you use the resource() method, which will in addition to generating API specific routes, also generate create and edit routes, which aren’t needed when building an API.