Skip to content

Instantly share code, notes, and snippets.

@tiagomatosweb
Last active February 6, 2020 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagomatosweb/5fef9a737196dec6385b8e434708fa8f to your computer and use it in GitHub Desktop.
Save tiagomatosweb/5fef9a737196dec6385b8e434708fa8f to your computer and use it in GitHub Desktop.
<?php
namespace App\V1\User\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$avatar = $this->avatar ? Storage::url($this->avatar) : '';
if (!empty($this->socialAccounts->provider_name) && $this->socialAccounts->provider_name === 'facebook') {
$avatar = "https://graph.facebook.com/v5.0/{$this->socialAccounts->social_id}/picture?type=normal";
}
return [
'id' => (integer)$this->id,
'first_name' => (string)$this->first_name,
'last_name' => (string)$this->last_name,
'email' => (string)$this->email,
'address' => (string)$this->address,
'suburb' => (string)$this->suburb,
'postcode' => (string)$this->postcode,
'city' => (string)$this->city,
'avatar' => (string)avatar,
'contact_number' => (string)$this->contact_number,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment