File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed
src/Illuminate/Http/Resources/JsonApi
tests/Integration/Http/Resources/JsonApi Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,22 @@ public function toType(Request $request)
7171 return null ;
7272 }
7373
74+ /**
75+ * Transform the resource into an array.
76+ *
77+ * @param \Illuminate\Http\Request $request
78+ * @return \Illuminate\Contracts\Support\Arrayable|\JsonSerializable|array
79+ */
80+ #[\Override]
81+ public function toAttributes (Request $ request )
82+ {
83+ if (property_exists ($ this , 'attributes ' )) {
84+ return $ this ->attributes ;
85+ }
86+
87+ return $ this ->toArray ($ request );
88+ }
89+
7490 /**
7591 * Get the resource's links.
7692 *
Original file line number Diff line number Diff line change @@ -186,13 +186,10 @@ public function user()
186186
187187class PostApiResource extends JsonApiResource
188188{
189- public function toAttributes (Request $ request )
190- {
191- return [
192- 'title ' ,
193- 'content ' ,
194- ];
195- }
189+ protected array $ attributes = [
190+ 'title ' ,
191+ 'content ' ,
192+ ];
196193}
197194
198195class PostFactory extends Factory
You can’t perform that action at this time.
0 commit comments