Last active
February 6, 2020 22:24
-
-
Save tiagomatosweb/5fef9a737196dec6385b8e434708fa8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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