Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using MergeWhen twice, it adds a array to the Resource response. #21122

Closed
mwagena opened this issue Sep 11, 2017 · 2 comments
Closed

When using MergeWhen twice, it adds a array to the Resource response. #21122

mwagena opened this issue Sep 11, 2017 · 2 comments

Comments

@mwagena
Copy link

mwagena commented Sep 11, 2017

  • Laravel Version: 5.5.0
  • PHP Version: 7.1.3

Description:

When I use 'mergeWhen' twice, it adds a array to the Resource response. Is this meant to work like this?

Steps To Reproduce:

public function toArray($request) {
        return [
            'id' => $this->id,
            'date' => $this->end_date->format('Y-m-d'),
            'start_date' => $this->start_date->format('H:i'),
            'end_date' => $this->end_date->format('H:i'),
            $this->mergeWhen($request->user()->role !== 2, [
                'candidates' => ActivityCandidate::collection($this->activityCandidate)
            ]),
            $this->mergeWhen($request->user()->role === 2, [
                'is_accepted2' => $this->activityCandidate()->where('candidate_id', $request->user()->candidate->id)->first()->is_accepted,
            ]),
            'attachment_id' => $this->attachment_id,
            'attachment' => '',
            'department_id' => $this->department_id,
            'label_color' => $this->label_color,
            'instructions_general' => $this->instructions_general,
            'instructions_transport' => $this->instructions_transport,
            'send_notification_client' => $this->send_notification_client,
            'send_notification_mail' => $this->send_notification_mail,
            'send_notification_app' => $this->send_notification_app,
        ];
}

outputs:

{
            "1": {
                "data": {
                    "is_accepted2": false
                }
            },
            "id": 6,
            "date": "2017-09-09",
            "start_date": "08:00",
            "end_date": "19:00",
            "is_accepted2": false,
            "attachment": "",
            "department_id": 2,
            "label_color": "#e3e4e5",
            "instructions_general": "sadf",
            "instructions_transport": "sdf",
            "send_notification_client": false,
            "send_notification_mail": false,
            "send_notification_app": false
},
@Dylan-DPC-zz
Copy link

I don't think this is a bug. Use the forums or the slack channel to solve your issue out (if needed)

@themsaid
Copy link
Member

Thanks, PR opened at #21127

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

No branches or pull requests

3 participants