Skip to content

Conversation

@crynobone
Copy link
Member

@crynobone crynobone commented Oct 31, 2025

This is an improvements to #57571 and allows using toAttributes() method or $attributes property whenever possible.

Using property

class UserResource extends JsonApiResource
{
    protected $attributes = [
        'name',
        'email',
    ];
}

Using method

class UserResource extends JsonApiResource
{
    public function toAttributes(Request $request)
    {
        return [
            'name',
            'email',
            'avatar' => url("/images/profile/{$this->id}.png"),
        ];
}

crynobone and others added 7 commits October 31, 2025 11:30
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone crynobone marked this pull request as ready for review October 31, 2025 11:33
@taylorotwell taylorotwell merged commit 4abf43a into json-api-resource Oct 31, 2025
67 checks passed
@taylorotwell taylorotwell deleted the json-api-resource-to-attributes branch October 31, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants