update API profile member
This commit is contained in:
59
Modules/Linksehat/Transformers/User/UserProfileResource.php
Normal file
59
Modules/Linksehat/Transformers/User/UserProfileResource.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers\User;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Models\OLDLMS\User;
|
||||
use App\Models\OLDLMS\UserDetail;
|
||||
use DB;
|
||||
|
||||
|
||||
class UserProfileResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
|
||||
protected $connection = 'oldlms';
|
||||
|
||||
public function toArray($request)
|
||||
{
|
||||
$memberProfile = User::with('detail')->where('nIDUser', $this->nID)->get()->toArray();
|
||||
$dataMemberProfile = [];
|
||||
|
||||
if (count($memberProfile) > 0){
|
||||
foreach($memberProfile as $m){
|
||||
$urlAvatarDefault = $m['detail']['nIDJenisKelamin'] == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/male-avatar.png';
|
||||
$avatarMember = $m['detail']['sImage'] ?? $urlAvatarDefault;
|
||||
$relationship = DB::connection('oldlms')->table('tm_hubungan_keluarga')->where('nID', $m['nIDHubunganKeluarga'])->first('sHubunganKeluarga');
|
||||
|
||||
$data = [
|
||||
'id' => $m['nID'],
|
||||
'name' => $m['full_name'],
|
||||
'relationship' => $relationship->sHubunganKeluarga,
|
||||
'avatar' => $avatarMember,
|
||||
|
||||
];
|
||||
|
||||
array_push( $dataMemberProfile, $data);
|
||||
}
|
||||
}
|
||||
|
||||
// Principal
|
||||
$urlAvatarDefault = $this->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/male-avatar.png';
|
||||
$avatar = $this->detail->sImage ?? $urlAvatarDefault;
|
||||
|
||||
|
||||
return [
|
||||
'id' => $this->nID,
|
||||
'full_name' => $this->sFirstName . ' '. $this->sLastName,
|
||||
'avatar' => $avatar,
|
||||
'member_type' => $this->nIDUser ? 'Dependent' : 'Principal',
|
||||
'member_profile' => $dataMemberProfile,
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user