%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/news/app/Transformers/
Upload File :
Create Path :
Current File : /var/www/html/news/app/Transformers/UserTransformer.php

<?php

namespace App\Transformers;

use App\Models\User;

class UserTransformer extends BaseTransformer
{
    protected $availableIncludes = [
        'roles',
    ];

    public function transform(User $user)
    {
        $data = $this->transformColumns($user);
        $data['fullname'] = $user->present()->fullName;

        if ($user->media) {
            $data['profile_picture'] = $user->media->present()->getFullImageLink;
        } else {
            $data['profile_picture'] = 'images/avatar.jpg';
        }

        return $data;
    }

    public function includeRoles(User $user)
    {
        return $this->collection($user->roles, new RoleTransformer, 'roles');
    }

    protected function getTransformableColumns()
    {
        return [
            'id'         => 'id',
            'email'      => 'email',
            'name'       => 'name',
            'surname'    => 'surname',
            'birthdate'  => 'birthdate',
            'is_active'  => 'is_active',
            'created_at' => 'created_at',
            'updated_at' => 'updated_at'
        ];
    }

}

Zerion Mini Shell 1.0