Responses
Defining Responses
By default, Rest responses are stored in the app/Rest/Responses directory of your application. You may generate a new Response by using the rest:response Artisan command:
php artisan rest:response UserResponse
You are now free to modify the map method from your new Response:
/**
* This maps on each model returned by the API, use it at your ease.
*
* @var \Illuminate\Database\Eloquent\Model $model
* @var array $responseModel
*
* @return array
*/
protected function map(\Illuminate\Database\Eloquent\Model $model, array $responseModel) : array {
return $responseModel;
}
The $model represents the original model, whereas $responseModel is the response that would typically be initiated by Laravel Rest Api.
Registering Responses
You now have to specify the Response within the corresponding Resource file.
/**
* The reponse the entry corresponds to.
*
* @var class-string<Response>
*/
public static $response = App\Rest\Responses\UserResponse::class;
Instructions
Instructions are a way to provide customization to your search requests fully depending on your needs. They give you full access to the query.
Documentation
Laravel Rest API provides first-class integration with Scramble to automatically generate your API documentation from your resources, fields, relations and validation rules — with zero manual configuration.