You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -78,6 +78,22 @@ Returns a `201` HTTP status code, with response optional data
78
78
79
79
Returns a `204` HTTP status code, with optional response data. Strictly speaking, the response body should be empty. However, functionality to optionally return data was added to handle legacy projects. Within your own projects, you can simply call the method, omitting parameters, to generate a correct `204` response i.e. `return $this->respondNoContent()`
80
80
81
+
## Additional Data Types
82
+
83
+
In addition to a plain PHP `array`, the following data types can be passed to relevant methods:
84
+
85
+
- Objects implementing the Laravel `Illuminate\Contracts\Support\Arrayable` contract
86
+
- Objects implementing the native PHP `JsonSerializable` contract
87
+
88
+
This allows a variety of object types to be passed and converted automatically.
89
+
90
+
Some example objects that can be passed (there are a lot more):
-`Illuminate\Http\Resources\Json\JsonResource` (i.e. [Laravel API resources](https://laravel.com/docs/8.x/eloquent-resources))
95
+
-`Illuminate\Foundation\Http\FormRequest`
96
+
81
97
## Motivation
82
98
83
99
Ensure consistent JSON API responses throughout an application. The motivation was primarily based on a very old inherited Laravel project. The project contained a plethora of methods/structures used to return an error:
0 commit comments