Files
crater/app/Http/Resources/UserResource.php
Mohit Panjwani 082d5cacf2 v5.0.0 update
2021-11-30 18:58:19 +05:30

46 lines
1.5 KiB
PHP

<?php
namespace Crater\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'phone' => $this->phone,
'role' => $this->role,
'contact_name' => $this->contact_name,
'company_name' => $this->company_name,
'website' => $this->website,
'enable_portal' => $this->enable_portal,
'currency_id' => $this->currency_id,
'facebook_id' => $this->facebook_id,
'google_id' => $this->google_id,
'github_id' => $this->github_id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'avatar' => $this->avatar,
'is_owner' => $this->isOwner(),
'roles' => $this->roles,
'formatted_created_at' => $this->formattedCreatedAt,
'currency' => $this->when($this->currency()->exists(), function () {
return new CurrencyResource($this->currency);
}),
'companies' => $this->when($this->companies()->exists(), function () {
return CompanyResource::collection($this->companies);
})
];
}
}