Files
wticreatorstudio/Modules/Staff/Transformers/StaffResource.php
T
2024-04-03 02:15:14 -04:00

57 lines
2.0 KiB
PHP

<?php
namespace Modules\Staff\Transformers;
use Illuminate\Http\Resources\Json\JsonResource;
use Modules\StudioPlus\Entities\StudioPlusVideo;
use App\Models\User;
class StaffResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
$upline = null;
if($this->user->parent_id != null){
$upline = User::find($this->user->parent_id);
if($upline){
$upline = $upline->name;
}
}
$published_videos = StudioPlusVideo::whereHas('channel', function($query){
$query->where('user_id', $this->user->id);
})->where('status',StudioPlusVideo::STATUS_PUBLISHED)->count();
return [
'id' => $this->id,
'user_id' => $this->user->id,
'first_name' => $this->user->first_name,
'last_name' => $this->user->last_name,
'name' => $this->user->name,
'username' => $this->user->username,
'date_of_birth' => $this->user->date_of_birth,
'email' => $this->user->email,
'phone' => $this->user->phone,
'avatar' => $this->user->avatar != null ? url("/public/{$this->user->avatar}") : null,
'ott_photo' => $this->ott_photo != null ? url("/public/{$this->ott_photo}") : null,
'upline' => $upline,
'role_id' => $this->user->role->id,
'role' => $this->user->role->name,
'badges' => $this->badges,
'department_id' => $this->department->id,
'department' => $this->department->name,
'parent_id' => $this->user->parent_id,
'is_active' => (boolean)$this->user->is_active,
'published_videos' => $published_videos,
'created_at' => $this->created_at->format('Y-m-d'),
'updated_at' => $this->updated_at,
];
}
}