o create API resources and an API ResourcesController for handling requests and responses in Laravel, you can follow these steps: Create API Resource: API resources are used to format the JSON response for single model instances. In your case, the UserResource class is an example of an API resource. bash Copy code php artisan make:resource UserResource After running this command, Laravel will create a new UserResource.php file in the app/Http/Resources directory. Here's an example of how your UserResource might look: php Copy code <?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; class UserResource extends JsonResource { public function toArray($request) { return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, // other attributes you want to include ]; } } Create API ResourcesController: The API ResourcesController is where you define methods to handle incoming requests and return responses using your API resources. bash Copy code php artisan make:controller API\ResourcesController After running this command, Laravel will create a new ResourcesController.php file in the app/Http/Controllers/API directory. Here's an example of how your ResourcesController might look: php Copy code <?php namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use App\Http\Resources\UserResource; use App\Http\Resources\UserResourceCollection; use App\Models\User; use Illuminate\Http\Request; class ResourcesController extends Controller { public function getUserDetails(Request $request) { $users = User::get(); // Fetch all users // Return a single user's details using UserResource // return new UserResource($users->first()); // Return a collection of users' details using UserResourceCollection return new UserResourceCollection($users); } } Register Routes: Finally, you need to register routes in your routes/api.php file to map incoming requests to the appropriate controller methods. php Copy code use App\Http\Controllers\API\ResourcesController; Route::get('/users', [ResourcesController::class, 'getUserDetails']); Now, when you send a GET request to /api/users, Laravel will invoke the getUserDetails method in your ResourcesController, which will return the JSON response formatted using either UserResource for a single user or UserResourceCollection for a collection of users, depending on which resource you choose to return.When declaring resource routes that will be consumed by APIs, you will commonly want to exclude routes that present HTML templates such as "create" and "edit" //Route=> use App\Http\Controllers\PhotoController; Route::apiResource('photos', PhotoController::class); //artisan command => php artisan make:controller PhotoController --api Verb Path Action Route Name GET /users index users.index POST /users store users.store GET /users/{user} show users.show PUT|PATCH /users/{user} update users.update DELETE /users/{user} destroy users.destroyhp artisan make:model Product -a --apiphp artisan make:controller PhotoController --apiphp artisan make:resource User --collection php artisan make:resource UserCollectionphp artisan make:resource UserResource php artisan make:resource User --collection php artisan make:resource UserCollectionGET - "/photos/{photo}/comments" - index GET - "/photos/{photo}/comments/create" - create POST - "/photos/{photo}/comments" - store GET - "/comments/{comment}" - show GET - "/comments/{comment}/edit" - edit PUT/PATCH - "/comments/{comment}" - update DELETE - "/comments/{comment}" - destroy