Completed
Push — master ( ec7d58...d2da01 )
by Innocent
04:23
created

DiscussionList::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Faithgen\Discussions\Http\Resources;
4
5
use FaithGen\SDK\Helpers\ImageHelper;
6
use Illuminate\Http\Resources\Json\JsonResource;
7
use Illuminate\Support\Str;
8
use InnoFlash\LaraStart\Helper;
9
10
class DiscussionList extends JsonResource
11
{
12
    /**
13
     * Transform the resource into an array.
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     *
17
     * @return array
18
     */
19
    public function toArray($request)
20
    {
21
        if ($is_admin = Str::of($this->discussable_type)->contains('Ministry')) {
22
            $avatar =
23
                ImageHelper::getImage('profile', $this->discussable->image, config('faithgen-sdk.ministries-server'));
24
        } else {
25
            $avatar = ImageHelper::getImage('users', $this->discussable->image, config('faithgen-sdk.users-server'));
26
        }
27
28
        return [
29
            'id'       => $this->id,
30
            'title'    => $this->title,
31
            'approved' => (bool) $this->approved,
32
            'creator'  => [
33
                'id'       => $this->discussable_id,
34
                'name'     => $this->discussable->name,
35
                'is_admin' => $is_admin,
36
                'avatar'   => $avatar,
37
            ],
38
            'date'     => Helper::getDates($this->created_at),
39
        ];
40
    }
41
}
42